Part Number Hot Search : 
BYX103G 128M000 STX0560 LX723 PEB2086 B2100 XMEGAA09 000AA
Product Description
Full Text Search
 

To Download SAFC166 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  microcontrollers c166 family 16-bit single-chip microcontroller c161pi user?s manual 1999-08 v 1.0 www.infineon.com
ed i t ion 1999-08 p u b l i s h e d by infineo n t e c hnol o gies a g, s t.-ma r tin-stra s se 53 d - 815 4 1 mnchen ? infi n eo n t echno l ogies a g 1999. all righ t s r e se r ved. attenti o n p l ease! t h e i n f o r matio n her e in i s gi v e n to desc r ibe c e r t a in c o mp o ne n ts and sh a ll n ot be con- s i d e r e d as w a r r a n t ed c ha r a ct e r i st i c s . t e r ms of d e l i v e r y a n d r i g hts to t e chn i c a l c h an g e rese r v e d. we h er e b y disclaim any and a l l wa r r a nties, inc l u d i n g b ut n o t l im i ted to w a rr ant i es of non- i nf r i ngement, r ega r din g ci r c u its, de- sc r i p ti o ns a n d cha r ts state d h e rei n . infineon t echnologies is an appr o v ed c e cc manu f a ctu r e r . in f o r mation for f u r th e r info r m a ti o n on t e c h n o l o g y , de - live r y te r ms and co n diti o ns a n d p r ices p le a se contact your n e arest infin e o n t ech- n ol o gies off i ce in g e r many or o u r infi n eon t ech n ol o gi e s rep r ese n t a t i v es wo r l d wide ( s e e ad d ress l i st). w arn i ngs d u e to t e c h nical req u ireme n ts c o mpon e nts m a y co n t a in d a ng e rous substances. f or in- f o r mat i o n o n t h e typ e s i n q ues t i o n p l e a se c o ntact your n e arest i n fi n eon t echn o logi e s of f i c e . inf i neon t echno l ogies compon e nts m a y o nly be u sed in l i f e -sup p o r t d e vices or sys- t e ms with th e e xp r ess written app r o v al of inf i neon t ec h nolog i es, if a f a i lur e of such components can re a sona b ly b e e xpected to ca u se t h e f ail u re of that li f e-su p po r t de- vice or system, or to af f ect the s a f e ty o r e f- f ecti v eness of that d e vice or system. li f e s u pp o r t d e vices or systems are i n t e nd e d to b e impl a nted in the h uman b od y , or to sup- p o r t and/or ma i ntai n and sustain and/or p rotect h uman li f e. if th e y f a il, it is r e ason- a b le to a ssume t h at t h e he a lth of t h e user o r other p e rsons m a y be e n dan g er e d. a usgabe 19 99 -08 heraus g ege b en v on i n f i n e o n t ec h n o l o g i es a g, st.-ma r tin-st r asse 53 d-81 5 41 m n c hen ? i nfineon t ec h nol o gies a g 1999. alle rechte v orbehalten. wichtige hinweis e ! mit d e n a ng a ben w e rd e n d i e ba u elem e nte spezifizie r t, nicht eigenschaften zuges i - che r t. li e f e r m? g lichke i t e n u n d t e chnisc h e ? nd e - r u n gen sind vorb e halte n . fr die an g eg e be n en s c h altun g en, b e - sc h rei b u ng e n und t ab e llen wird k e i ne g e - w?hr bez glic h de r f rei h eit v o n recht e n dr i tt e r o d e r d e r e n r i c h t i g k e i t b e r n om- men. i n f i ne o n t echn o logi e s ist ein hersteller v o n cecc-q u alifizie r t e n pr o dukten. a u s k nfte f r a g e n be r t ec h n i k , p r e i s e , l i e f e r m ? g- l i ch k eiten und -bedingunge n r ic h ten sie bitte an den i h nen n ? chstgelegenen v e r - t r ieb infine o n t ech n olo g ies in deutsc h la n d ode r an unser e v e r triebsstel l en im a us- la n d. w a rnhin w eise b a u e lem e nte k ? n ne n a u f g r u n d t ec h n i - sche r e r f o rd e r n isse g e f a hrstof f e entha l - t e n. a u s k nfte dar be r bitt e n wir u n t e r a n - ga b e d es betr e f f e n den t yps e b en f a lls b e r d en v e r tri e b i n fi n e o n t e chn o l og i es e i n zu- ho l en. i n f i ne o n t e c h nol o gies b au e leme n te d r f e n nur mit ausd r c klich e r sc h r iftlic h er g e ne h - migung v on inf i neo n t e chn o logies i n l e- b e nser h alt e nde n ge r ? ten od e r syst e men eingesetzt werden, f alls beim a us f all des ba u el e m e ntes b e rechtigter g r und zur a n - na h me besteht, d a ? d as l eb e nserh a lten d e g e r ? t o d er s ystem a usf ? llt bz w . d e ss e n s i- c h e r h e it o de r wirksam k e i t b e e i n t r ? chtigt wird. l eb e nser h alten d e g er ? te und syst e - me sind zur chirurgischen einpflan z ung in den me n schlichen k ? r per ge d ac h t o d er unterst tzen bz w . erhalten das menschl i - c h e leben. sollt e n sie a u s f allen, b esteht be r echtigter g r und z u r a n na h m e , da ? d i e g e s u nd h eit d es a nw e nd e rs g e f ? hrd e t w e r- den k a nn.
microcontrollers c166 family 16-bit single-chip microcontroller c161pi v 1.0, 1999-08 user ? s manual
the c161pi is the successor of the c161ri . therefore this manual also replaces the c161ri manual. c161pi revision history: 1999-08 (v 1.0) previous versions: user ? s manual c161ri, 05.98 (v 1.0) page subjects (major changes since last revision) we listen to your comments any information within this document that you feel is wrong, unclear or missing at all? your feedback will help us to continuously improve the quality of this document. please send your proposal (including a reference to this document) to: mcdocu.comments@infineon.com
c161pi table of contents page user ? s manual -1 1999-08 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1.1 the members of the 16-bit microcontroller family . . . . . . . . . . . . . . . . . . 1-2 1.2 summary of basic features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 1.3 abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 2 architectural overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1 2.1 basic cpu concepts and optimizations . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 2.1.1 high instruction bandwidth / fast execution . . . . . . . . . . . . . . . . . . . . . 2-3 2.1.2 programmable multiple priority interrupt system . . . . . . . . . . . . . . . . . 2-7 2.2 the on-chip system resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 2.3 the on-chip peripheral blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 2.4 power management features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 2.5 protected bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 3 memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1 3.1 internal rom area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 3.2 internal ram and sfr area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 3.3 the on-chip xram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 3.4 external memory space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11 3.5 crossing memory boundaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 4 the central processing unit (cpu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 4.1 instruction pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 4.2 particular pipeline effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7 4.3 bit-handling and bit-protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 4.4 instruction state times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 4.5 cpu special function registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13 5 interrupt and trap functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1 5.1 interrupt system structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 5.1.1 interrupt control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 5.2 operation of the pec channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11 5.3 prioritization of interrupt and pec service requests . . . . . . . . . . . . . . . 5-15 5.4 saving the status during interrupt service . . . . . . . . . . . . . . . . . . . . . . . 5-17 5.5 interrupt response times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18 5.6 pec response times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21 5.7 interrupt node sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23 5.8 external interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-24 5.9 trap functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29 6 clock generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1 6.1 oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 6.2 frequency control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 6.3 oscillator watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
c161pi table of contents page user ? s manual -2 1999-08 6.4 clock drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9 7 parallel ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1 7.1 input threshold control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 7.2 output driver control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 7.3 alternate port functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 7.4 port0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 7.5 port1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-13 7.6 port 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 7.7 port 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19 7.8 port 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-24 7.9 port 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27 7.10 port 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30 8 dedicated pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1 9 the external bus interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-1 9.1 single chip mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 9.2 external bus modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3 9.3 programmable bus characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-12 9.4 ready controlled bus cycles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-17 9.5 controlling the external bus controller . . . . . . . . . . . . . . . . . . . . . . . . . . 9-19 9.6 ebc idle state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-27 9.7 the xbus interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-28 10 the general purpose timer units . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1 10.1 timer block gpt1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1 10.1.1 gpt1 core timer t3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3 10.1.2 gpt1 auxiliary timers t2 and t4 . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13 10.1.3 interrupt control for gpt1 timers . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22 10.2 timer block gpt2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23 10.2.1 gpt2 core timer t6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-25 10.2.2 gpt2 auxiliary timer t5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-28 10.2.3 interrupt control for gpt2 timers and caprel . . . . . . . . . . . . . . . . 10-36 11 the asynchronous/synchronous serial interface . . . . . . . . . . . . . . 11-1 11.1 asynchronous operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5 11.2 synchronous operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8 11.3 hardware error detection capabilities . . . . . . . . . . . . . . . . . . . . . . . . . 11-10 11.4 asc0 baud rate generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11 11.5 asc0 interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-15 12 the high-speed synchronous serial interface . . . . . . . . . . . . . . . . . 12-1 12.1 full-duplex operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-7 12.2 half duplex operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-10
c161pi table of contents page user ? s manual -3 1999-08 12.3 continuous transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-11 12.4 port control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-12 12.5 baud rate generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-13 12.6 error detection mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-14 12.7 ssc interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-16 13 the watchdog timer (wdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-1 13.1 operation of the watchdog timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-3 13.2 reset source indication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-6 14 the real time clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-1 15 the bootstrap loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1 16 the analog / digital converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-1 16.1 mode selection and operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2 16.2 conversion timing control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-11 16.3 a/d converter interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-13 17 the i2c bus module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-1 17.1 i2c bus conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2 17.2 the physical i2c bus interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4 17.3 operating the i2c bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-6 17.3.1 operation in master mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-6 17.3.2 operation in multimaster mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-7 17.3.3 operation in slave mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-7 17.4 i2c interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-12 17.5 programming example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-14 18 system reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-1 18.1 reset sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-2 18.2 status after reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-5 18.3 application-specific initialization routine . . . . . . . . . . . . . . . . . . . . . . . . 18-9 18.4 system startup configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-12 18.4.1 system startup configuration upon an external reset . . . . . . . . . . 18-13 18.4.2 system startup configuration upon a single-chip mode reset . . . 18-20 19 power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-1 19.1 idle mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-3 19.2 sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-5 19.3 power down mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-7 19.3.1 status of output pins during power reduction modes . . . . . . . . . . . . 19-8 19.4 slow down operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-10 19.5 flexible peripheral management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-14 19.6 programmable frequency output signal . . . . . . . . . . . . . . . . . . . . . . 19-16
c161pi table of contents page user ? s manual -4 1999-08 19.7 security mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-20 20 system programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-1 20.1 stack operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-4 20.2 register banking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-9 20.3 procedure call entry and exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-9 20.4 table searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-12 20.5 floating point support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-12 20.6 peripheral control and interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-13 20.7 trap/interrupt entry and exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-13 20.8 unseparable instruction sequences . . . . . . . . . . . . . . . . . . . . . . . . . . 20-14 20.9 overriding the dpp addressing mechanism . . . . . . . . . . . . . . . . . . . . 20-14 20.10 handling the internal code memory . . . . . . . . . . . . . . . . . . . . . . . . . . 20-16 20.11 pits, traps and mines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-18 21 the register set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-1 21.1 register description format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-1 21.2 cpu general purpose registers (gprs) . . . . . . . . . . . . . . . . . . . . . . . . 21-2 21.3 special function registers ordered by name . . . . . . . . . . . . . . . . . . . . 21-4 21.4 registers ordered by address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-9 21.5 special notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-14 22 instruction set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-1 23 device specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-1 24 keyword index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-1
 
  user ? s manual 1-1 1999-08  1introduction the rapidly growing area of embedded control applications is representing one of the most time-critical operating environments for today ? s microcontrollers. complex control algorithms have to be processed based on a large number of digital as well as analog input signals, and the appropriate output signals must be generated within a defined maximum response time. embedded control applications also are often sensitive to board space, power consumption, and overall system cost. embedded control applications therefore require microcontrollers, which...  offer a high level of system integration  eliminate the need for additional peripheral devices and the associated software overhead  provide system security and fail-safe mechanisms  provide effective means to control (and reduce) the device ? s power consumption. with the increasing complexity of embedded control applications, a significant increase in cpu performance and peripheral functionality over conventional 8-bit controllers is required from microcontrollers for high-end embedded control systems. in order to achieve this high performance goal infineon has decided to develop its family of 16-bit cmos microcontrollers without the constraints of backward compatibility. of course the architecture of the 16-bit microcontroller family pursues successfull hardware and software concepts, which have been established in infineons popular 8- bit controller families. about this manual this manual describes the functionality of the 16-bit microcontroller c161pi of the infineon c166 family. the descriptions in this manual refer to the following derivatives:  c161pi-lm  c161pi-lf this manual is valid for the mentioned derivatives. of course it refers to all devices of the different available temperature ranges and packages. for simplicity all these various versions are referred to by the term c161pi throughout this manual. the complete pro-electron conforming designations are listed in the respective data sheets.
 
  user ? s manual 1-2 1999-08  1.1 the members of the 16-bit microcontroller family the microcontrollers of the infineon 16-bit family have been designed to meet the high performance requirements of real-time embedded control applications. the architecture of this family has been optimized for high instruction throughput and minimum response time to external stimuli (interrupts). intelligent peripheral subsystems have been integrated to reduce the need for cpu intervention to a minimum extent. this also minimizes the need for communication via the external bus interface. the high flexibility of this architecture allows to serve the diverse and varying needs of different application areas such as automotive, industrial control, or data communications. the core of the 16-bit family has been developped with a modular family concept in mind. all family members execute an efficient control-optimized instruction set (additional instructions for members of the second generation). this allows an easy and quick implementation of new family members with different internal memory sizes and technologies, different sets of on-chip peripherals and/or different numbers of io pins. the xbus concept opens a straight forward path for the integration of application specific peripheral modules in addition to the standard on-chip peripherals in order to build application specific derivatives. as programs for embedded control applications become larger, high level languages are favoured by programmers, because high level language programs are easier to write, to debug and to maintain. the 80c166-type microcontrollers were the first generation of the 16-bit controller family. these devices have established the c166 architecture. the c165-type and c167-type devices are members of the second generation of this family. this second generation is even more powerful due to additional instructions for hll support, an increased address space, increased internal ram and highly efficient management of various resources on the external bus. enhanced derivatives of this second generation provide additional features like additional internal high-speed ram, an integrated can-module, an on-chip pll, etc. utilizing integration to design efficient systems may require the integration of application specific peripherals to boost system performance, while minimizing the part count. these efforts are supported by the so-called xbus, defined for the infineon 16-bit microcontrollers (second generation). this xbus is an internal representation of the external bus interface that opens and simplifies the integration of peripherals by standardizing the required interface. one representative taking advantage of this technology is the integrated can module. the c165-type devices are reduced versions of the c167 which provide a smaller package and reduced power consumption at the expense of the a/d converter, the capcom units and the pwm module.
 
  user ? s manual 1-3 1999-08  the c164-type devices and some of the c161-type devices are further enhanced by a flexible power management and form the third generation of the 16-bit controller family. this power management mechanism provides effective means to control the power that is consumed in a certain state of the controller and thus allows the minimization of the overall power consumption with respect to a given application. a variety of different versions is provided which offer various kinds of on-chip program memory:  mask-programmable rom  flash memory  otp memory  romless with no non-volatile memory at all. also there are devices with specific functional units. the devices may be offered in different packages, temperature ranges and speed classes. more standard and application-specific derivatives are planned and in development. note: not all derivatives will be offered in any temperature range, speed class, package or program memory variation. information about specific versions and derivatives will be made available with the devices themselves. contact your infineon representative for up-to-date material. note: as the architecture and the basic features (i.e. cpu core and built in peripherals) are identical for most of the currently offered versions of the c161pi, the descriptions within this manual that refer to the ?c161pi? also apply to the other variations, unless otherwise noted.
 
  user ? s manual 1-4 1999-08  1.2 summary of basic features the c161pi is an improved representative of the infineon family of full featured 16-bit single-chip cmos microcontrollers. it combines high cpu performance (up to 10 million instructions per second) with high peripheral functionality and means for power reduction. several key features contribute to the high performance of the c161pi (the indicated timings refer to a cpu clock of 25 mhz ). high performance 16-bit cpu with four-stage pipeline  80 ns minimum instruction cycle time, with most instructions executed in 1 cycle  400 ns multiplication (16-bit *16-bit), 800 ns division (32-bit/16-bit)  multiple high bandwidth internal data buses  register based design with multiple variable register banks  single cycle context switching support  16 mbytes linear address space for code and data (von neumann architecture)  system stack cache support with automatic stack overflow/underflow detection control oriented instruction set with high efficiency  bit, byte, and word data types  flexible and efficient addressing modes for high code density  enhanced boolean bit manipulation with direct addressability of 6 kbits for peripheral control and user defined flags  hardware traps to identify exception conditions during runtime  hll support for semaphore operations and efficient data access power management features  programmable system slowdown (slowdown divider sdd)  flexible peripheral management (individual disabling)  sleepmode including wakeup via external interrupts  programmable frequency output integrated on-chip memory  1 kbyte internal ram for variables, register banks, system stack and code  2 kbyte on-chip high-speed xram for variables, user stack and code external bus interface  multiplexed or demultiplexed bus configurations  segmentation capability and chip select signal generation  8-bit or 16-bit data bus  bus cycle characteristics selectable for five programmable address areas
 
  user ? s manual 1-5 1999-08  16-priority-level interrupt system  27 interrupt nodes with separate interrupt vectors  240/400 ns typical/maximum interrupt latency in case of internal program execution  fast external interrupts 8-channel peripheral event controller (pec)  interrupt driven single cycle data transfer  transfer count option (std. cpu interrupt after programmable number of pec transfers)  eliminates overhead of saving and restoring system state for interrupt requests intelligent on-chip peripheral subsystems  4-channel 10-bit a/d converter with programmable conversion time (7.76 s minimum), auto scan modes, channel injection mode  2 multifunctional general purpose timer units gpt1: three 16-bit timers/ counters, maximum resolution  cpu /8 gpt2: two 16-bit imers/counters, maximum resolution  cpu /4  asynchronous/synchronous serial channel (usart) with baud rate generator, parity, framing, and overrun error detection  high speed synchronous serial channel programmable data length and shift direction  i 2 c bus module with 10-bit addressing and 400 kbit/sec  real time clock  watchdog timer with programmable time intervals  bootstrap loader for flexible system initialization 76 io lines with individual bit addressability  tri-stated in input mode  push/pull or open drain output mode  programmable port driver control (fast/reduced edge) different temperature ranges  0 to +70 c, ? 40 to +85 c infineon cmos process  low power cmos technology including power saving idle, sleep and power down modes with flexible power management. 100-pin plastic quad flat pack (pqfp) packages  p-mqfp, 4*20 mm body, 0.65 mm (25.6 mil) lead spacing, surface mount technology  p-tqfp, 14*14 mm body, 0.5 mm (19.7 mil) lead spacing, surface mount technology
 
  user ? s manual 1-6 1999-08  complete development support for the development tool support of its microcontrollers, infineon follows a clear third party concept. currently around 120 tool suppliers world-wide, ranging from local niche manufacturers to multinational companies with broad product portfolios, offer powerful development tools for the infineon c500 and c166 microcontroller families, guaranteeing a remarkable variety of price-performance classes as well as early availability of high quality key tools such as compilers, assemblers, simulators, debuggers or in-circuit emulators. infineon incorporates its strategic tool partners very early into the product development process, making sure embedded system developers get reliable, well-tuned tool solutions, which help them unleash the power of infineon microcontrollers in the most effective way and with the shortest possible learning curve. the tool environment for the infineon 16-bit microcontrollers includes the following tools:  compilers (c, modula2, forth)  macro-assemblers, linkers, locaters, library managers, format-converters  architectural simulators  hll debuggers  real-time operating systems  vhdl chip models  in-circuit emulators (based on bondout or standard chips)  plug-in emulators  emulation and clip-over adapters, production sockets  logic analyzer disassemblers  starter kits  evaluation boards with monitor programs  industrial boards (also for can, fuzzy, profibus, forth applications)  network driver software (can, profibus)
 
  user ? s manual 1-7 1999-08  1.3 abbreviations the following acronyms and termini are used within this document: adc analog digital converter ale address latch enable alu arithmetic and logic unit asc asynchronous/synchronous serial controller cisc complex instruction set computing cmos complementary metal oxide silicon cpu central processing unit ebc external bus controller esfr extended special function register flash non-volatile memory that may be electrically erased gpr general purpose register gpt general purpose timer unit hll high level language i 2 c inter integrated circuit (bus) io input / output otp one time programmable memory pec peripheral event controller pla programmable logic array pll phase locked loop pwm pulse width modulation ram random access memory risc reduced instruction set computing rom read only memory sdd slow down divider sfr special function register ssc synchronous serial controller xbus internal representation of the external bus
 
  user ? s manual 1-8 1999-08 
       user ? s manual 2-1 1999-08  2 architectural overview the architecture of the c161pi combines the advantages of both risc and cisc processors in a very well-balanced way. the sum of the features which are combined result in a high performance microcontroller, which is the right choice not only for today ? s applications, but also for future engineering challenges. the c161pi not only integrates a powerful cpu core and a set of peripheral units into one chip, but also connects the units in a very efficient way. one of the four buses used concurrently on the c161pi is the xbus, an internal representation of the external bus interface. this bus provides a standardized method of integrating application-specific peripherals to produce derivates of the standard c161pi. figure 2-1 c161pi functional block diagram xram / can cpu core internal ram rom area xbus module i 2 c bus module interrupt controller pec wdt osc port0 port1 port 4 adc gpt1 ssc asc gpt2 rtc port 3 ext. ctrl port 6 port 5 bus xram port 2
       user ? s manual 2-2 1999-08  2.1 basic cpu concepts and optimizations the main core of the cpu consists of a 4-stage instruction pipeline, a 16-bit arithmetic and logic unit (alu) and dedicated sfrs. additional hardware is provided for a separate multiply and divide unit, a bit-mask generator and a barrel shifter. figure 2-2 cpu block diagram to meet the demand for greater performance and flexibility, a number of areas has been optimized in the processor core. functional blocks in the cpu core are controlled by signals from the instruction decode logic. these are summarized below, and described in detail in the following sections: 1) high instruction bandwidth / fast execution 2) high function 8-bit and 16-bit arithmetic and logic unit 3) extended bit processing and peripheral control 4) high performance branch-, call-, and loop processing 5) consistent and optimized instruction formats 6) programmable multiple priority interrupt structure
       user ? s manual 2-3 1999-08  2.1.1 high instruction bandwidth / fast execution based on the hardware provisions, most of the c161pi ? s instructions can be executed in just one machine cycle, which requires 2 cpu clock cycles (2 * 1/  cpu = 4 tcl). for example, shift and rotate instructions are always processed within one machine cycle, independent of the number of bits to be shifted. branch-, multiply- and divide instructions normally take more than one machine cycle. these instructions, however, have also been optimized. for example, branch instructions only require an additional machine cycle, when a branch is taken, and most branches taken in loops require no additional machine cycles at all, due to the so-called ? jump cache ? . a 32-bit / 16-bit division takes 20 cpu clock cycles, a 16-bit * 16-bit multiplication takes 10 cpu clock cycles. the instruction cycle time has been dramatically reduced through the use of instruction pipelining. this technique allows the core cpu to process portions of multiple sequential instruction stages in parallel. the following four stage pipeline provides the optimum balancing for the cpu core: fetch: in this stage, an instruction is fetched from the internal rom or ram or from the external memory, based on the current ip value. decode: in this stage, the previously fetched instruction is decoded and the required operands are fetched. execute: in this stage, the specified operation is performed on the previously fetched operands. write back: in this stage, the result is written to the specified location. if this technique were not used, each instruction would require four machine cycles. this increased performance allows a greater number of tasks and interrupts to be processed. instruction decoder instruction decoding is primarily generated from pla outputs based on the selected opcode. no microcode is used and each pipeline stage receives control signals staged in control registers from the decode stage plas. pipeline holds are primarily caused by wait states for external memory accesses and cause the holding of signals in the control registers. multiple-cycle instructions are performed through instruction injection and simple internal state machines which modify required control signals.
       user ? s manual 2-4 1999-08  high function 8-bit and 16-bit arithmetic and logic unit all standard arithmetic and logical operations are performed in a 16-bit alu. in addition, for byte operations, signals are provided from bits six and seven of the alu result to correctly set the condition flags. multiple precision arithmetic is provided through a ? carry-in ? signal to the alu from previously calculated portions of the desired operation. most internal execution blocks have been optimized to perform operations on either 8- bit or 16-bit quantities. once the pipeline has been filled, one instruction is completed per machine cycle, except for multiply and divide. an advanced booth algorithm has been incorporated to allow four bits to be multiplied and two bits to be divided per machine cycle. thus, these operations use two coupled 16-bit registers, mdl and mdh, and require four and nine machine cycles, respectively, to perform a 16-bit by 16-bit (or 32- bit by 16-bit) calculation plus one machine cycle to setup and adjust the operands and the result. even these longer multiply and divide instructions can be interrupted during their execution to allow for very fast interrupt response. instructions have also been provided to allow byte packing in memory while providing sign extension of bytes for word wide arithmetic operations. the internal bus structure also allows transfers of bytes or words to or from peripherals based on the peripheral requirements. a set of consistent flags is automatically updated in the psw after each arithmetic, logical, shift, or movement operation. these flags allow branching on specific conditions. support for both signed and unsigned arithmetic is provided through user-specifiable branch tests. these flags are also preserved automatically by the cpu upon entry into an interrupt or trap routine. all targets for branch calculations are also computed in the central alu. a 16-bit barrel shifter provides multiple bit shifts in a single cycle. rotates and arithmetic shifts are also supported. extended bit processing and peripheral control a large number of instructions has been dedicated to bit processing. these instructions provide efficient control and testing of peripherals while enhancing data manipulation. unlike other microcontrollers, these instructions provide direct access to two operands in the bit-addressable space without requiring to move them into temporary flags. the same logical instructions available for words and bytes are also supported for bits. this allows the user to compare and modify a control bit for a peripheral in one instruction. multiple bit shift instructions have been included to avoid long instruction streams of single bit shift operations. these are also performed in a single machine cycle. in addition, bit field instructions have been provided, which allow the modification of multiple bits from one operand in a single instruction.
       user ? s manual 2-5 1999-08  high performance branch-, call-, and loop processing due to the high percentage of branching in controller applications, branch instructions have been optimized to require one extra machine cycle only when a branch is taken. this is implemented by precalculating the target address while decoding the instruction. to decrease loop execution overhead, three enhancements have been provided:  the first solution provides single cycle branch execution after the first iteration of a loop. thus, only one machine cycle is lost during the execution of the entire loop. in loops which fall through upon completion, no machine cycles are lost when exiting the loop. no special instructions are required to perform loops, and loops are automatically detected during execution of branch instructions.  the second loop enhancement allows the detection of the end of a table and avoids the use of two compare instructions embedded in loops. one simply places the lowest negative number at the end of the specific table, and specifies branching if neither this value nor the compared value have been found. otherwise the loop is terminated if either condition has been met. the terminating condition can then be tested.  the third loop enhancement provides a more flexible solution than the decrement and skip on zero instruction which is found in other microcontrollers. through the use of compare and increment or decrement instructions, the user can make comparisons to any value. this allows loop counters to cover any range. this is particularly advantageous in table searching. saving of system state is automatically performed on the internal system stack avoiding the use of instructions to preserve state upon entry and exit of interrupt or trap routines. call instructions push the value of the ip on the system stack, and require the same execution time as branch instructions. instructions have also been provided to support indirect branch and call instructions. this supports implementation of multiple case statement branching in assembler macros and high level languages.
       user ? s manual 2-6 1999-08  consistent and optimized instruction formats to obtain optimum performance in a pipelined design, an instruction set has been designed which incorporates concepts from reduced instruction set computing (risc). these concepts primarily allow fast decoding of the instructions and operands while reducing pipeline holds. these concepts, however, do not preclude the use of complex instructions, which are required by microcontroller users. the following goals were used to design the instruction set: 1. provide powerful instructions to perform operations which currently require sequences of instructions and are frequently used. avoid transfer into and out of temporary registers such as accumulators and carry bits. perform tasks in parallel such as saving state upon entry into interrupt routines or subroutines. 2. avoid complex encoding schemes by placing operands in consistent fields for each instruction. also avoid complex addressing modes which are not frequently used. this decreases the instruction decode time while also simplifying the development of compilers and assemblers. 3. provide most frequently used instructions with one-word instruction formats. all other instructions are placed into two-word formats. this allows all instructions to be placed on word boundaries, which alleviates the need for complex alignment hardware. it also has the benefit of increasing the range for relative branching instructions. the high performance offered by the hardware implementation of the cpu can efficiently be utilized by a programmer via the highly functional c161pi instruction set which includes the following instruction classes:  arithmetic instructions  logical instructions  boolean bit manipulation instructions  compare and loop control instructions  shift and rotate instructions  prioritize instruction  data movement instructions  system stack instructions  jump and call instructions  return instructions  system control instructions  miscellaneous instructions possible operand types are bits, bytes and words. specific instruction support the conversion (extension) of bytes to words. a variety of direct, indirect or immediate addressing modes are provided to specify the required operands.
       user ? s manual 2-7 1999-08  2.1.2 programmable multiple priority interrupt system the following enhancements have been included to allow processing of a large number of interrupt sources: 1. peripheral event controller (pec): this processor is used to off-load many interrupt requests from the cpu. it avoids the overhead of entering and exiting interrupt or trap routines by performing single-cycle interrupt-driven byte or word data transfers between any two locations in segment 0 with an optional increment of either the pec source or the destination pointer. just one cycle is ? stolen ? from the current cpu activity to perform a pec service. 2. multiple priority interrupt controller: this controller allows all interrupts to be placed at any specified priority. interrupts may also be grouped, which provides the user with the ability to prevent similar priority tasks from interrupting each other. for each of the possible interrupt sources there is a separate control register, which contains an interrupt request flag, an interrupt enable flag and an interrupt priority bitfield. once having been accepted by the cpu, an interrupt service can only be interrupted by a higher prioritized service request. for standard interrupt processing, each of the possible interrupt sources has a dedicated vector location. 3. 3)multiple register banks: this feature allows the user to specify up to sixteen general purpose registers located anywhere in the internal ram. a single one-machine-cycle instruction allows to switch register banks from one task to another. 4. 4)interruptable multiple cycle instructions: reduced interrupt latency is provided by allowing multiple-cycle instructions (multiply, divide) to be interruptable. with an interrupt response time within a range from just 5 to 10 cpu clock cycles (in case of internal program execution), the c161pi is capable of reacting very fast on non- deterministic events. its fast external interrupt inputs are sampled every cpu clock cycle and allow to recognize even very short external signals. the c161pi also provides an excellent mechanism to identify and to process exceptions or error conditions that arise during run-time, so called ? hardware traps ? . hardware traps cause an immediate non-maskable system reaction which is similiar to a standard interrupt service (branching to a dedicated vector table location). the occurrence of a hardware trap is additionally signified by an individual bit in the trap flag register (tfr). except for another higher prioritized trap service being in progress, a hardware trap will interrupt any current program execution. in turn, hardware trap services can normally not be interrupted by standard or pec interrupts. software interrupts are supported by means of the ? trap ? instruction in combination with an individual trap (interrupt) number.
       user ? s manual 2-8 1999-08  2.2 the on-chip system resources the c161pi controllers provide a number of powerful system resources designed around the cpu. the combination of cpu and these resources results in the high performance of the members of this controller family. peripheral event controller (pec) and interrupt control the peripheral event controller allows to respond to an interrupt request with a single data transfer (word or byte) which only consumes one instruction cycle and does not require to save and restore the machine status. each interrupt source is prioritized every machine cycle in the interrupt control block. if pec service is selected, a pec transfer is started. if cpu interrupt service is requested, the current cpu priority level stored in the psw register is tested to determine whether a higher priority interrupt is currently being serviced. when an interrupt is acknowledged, the current state of the machine is saved on the internal system stack and the cpu branches to the system specific vector for the peripheral. the pec contains a set of sfrs which store the count value and control bits for eight data transfer channels. in addition, the pec uses a dedicated area of ram which contains the source and destination addresses. the pec is controlled similar to any other peripheral through sfrs containing the desired configuration of each channel. an individual pec transfer counter is implicitly decremented for each pec service except forming in the continuous transfer mode. when this counter reaches zero, a standard interrupt is performed to the vector location related to the corresponding source. pec services are very well suited, for example, to move register contents to/from a memory table. the c161pi has 8 pec channels each of which offers such fast interrupt-driven data transfer capabilities. memory areas the memory space of the c161pi is configured in a von neumann architecture which means that code memory, data memory, registers and io ports are organized within the same linear address space which covers up to 16 mbytes. the entire memory space can be accessed bytewise or wordwise. particular portions of the on-chip memory have additionally been made directly bit addressable. a 1 kbyte 16-bit wide internal ram provides fast access to general purpose registers (gprs), user data (variables) and system stack. the internal ram may also be used for code. a unique decoding scheme provides flexible user register banks in the internal memory while optimizing the remaining ram for user data.
       user ? s manual 2-9 1999-08  the cpu disposes of an actual register context consisting of up to 16 wordwide and/or bytewide gprs, which are physically located within the on-chip ram area. a context pointer (cp) register determines the base address of the active register bank to be accessed by the cpu at a time. the number of register banks is only restricted by the available internal ram space. for easy parameter passing, a register bank may overlap others. a system stack of up to 512 words is provided as a storage for temporary data. the system stack is also located within the on-chip ram area, and it is accessed by the cpu via the stack pointer (sp) register. two separate sfrs, stkov and stkun, are implicitly compared against the stack pointer value upon each stack access for the detection of a stack overflow or underflow. hardware detection of the selected memory space is placed at the internal memory decoders and allows the user to specify any address directly or indirectly and obtain the desired data without using temporary registers or special instructions. a 2 kbyte 16-bit wide on-chip xram provides fast access to user data (variables), user stacks and code. the on-chip xram is realized as an x-peripheral and appears to the software as an external ram. therefore it cannot store register banks and is not bitaddressable. the xram allows 16-bit accesses with maximum speed. for special function registers 1024 bytes of the address space are reserved. the standard special function register area (sfr) uses 512 bytes, while the extended special function register area (esfr) uses the other 512 bytes. (e)sfrs are wordwide registers which are used for controlling and monitoring functions of the different on-chip units. unused (e)sfr addresses are reserved for future members of the c166 family with enhanced functionality.
       user ? s manual 2-10 1999-08  external bus interface in order to meet the needs of designs where more memory is required than is provided on chip, up to 8 mbytes of external ram and/or rom can be connected to the microcontroller via its external bus interface. the integrated external bus controller (ebc) allows to access external memory and/or peripheral resources in a very flexible way. for up to five address areas the bus mode (multiplexed / demultiplexed), the data bus width (8-bit/16-bit) and even the length of a bus cycle (waitstates, signal delays) can be selected independently. this allows to access a variety of memory and peripheral components directly and with maximum efficiency. if the device does not run in single chip mode, where no external memory is required, the ebc can control external accesses in one of the following external access modes:  16-/18-/20-/23-bit addresses, 16-bit data, demultiplexed  16-/18-/20-/23-bit addresses, 8-bit data, demultiplexed  16-/18-/20-/23-bit addresses, 16-bit data, multiplexed  16-/18-/20-/23-bit addresses, 8-bit data, multiplexed the demultiplexed bus modes use port1 for addresses and port0 for data input/ output. the multiplexed bus modes use port0 for both addresses and data input/ output. port 4 is used for the upper address lines (a16...) if selected. important timing characteristics of the external bus interface (waitstates, ale length and read/write delay) have been made programmable to allow the user the adaption of a wide range of different types of memories and/or peripherals. access to very slow memories or peripherals is supported via a particular 'ready' function. for applications which require less than 64 kbytes of address space, a non-segmented memory model can be selected, where all locations can be addressed by 16 bits, and thus port 4 is not needed as an output for the upper address bits (axx...a16), as is the case when using the segmented memory model. the on-chip xbus is an internal representation of the external bus and allows to access integrated application-specific peripherals/modules in the same way as external components. it provides a defined interface for these customized peripherals. the on-chip xram and the on-chip i 2 c-module are examples for these x-peripherals.
       user ? s manual 2-11 1999-08  2.3 the on-chip peripheral blocks the c166 family clearly separates peripherals from the core. this structure permits the maximum number of operations to be performed in parallel and allows peripherals to be added or deleted from family members without modifications to the core. each functional block processes data independently and communicates information over common buses. peripherals are controlled by data written to the respective special function registers (sfrs). these sfrs are located either within the standard sfr area (00 ? fe00 h ...00 ? ffff h ) or within the extended esfr area (00 ? f000 h ...00 ? f1ff h ). these built in peripherals either allow the cpu to interface with the external world, or provide functions on-chip that otherwise were to be added externally in the respective system. the c161pi generic peripherals are:  two general purpose timer blocks (gpt1 and gpt2)  two serial interfaces (asc0 and ssc)  a watchdog timer  an 8-bit analog / digital converter  a real time clock  seven io ports with a total of 76 io lines each peripheral also contains a set of special function registers (sfrs), which control the functionality of the peripheral and temporarily store intermediate data results. each peripheral has an associated set of status flags. individually selected clock signals are generated for each peripheral from binary multiples of the cpu clock. peripheral interfaces the on-chip peripherals generally have two different types of interfaces, an interface to the cpu and an interface to external hardware. communication between cpu and peripherals is performed through special function registers (sfrs) and interrupts. the sfrs serve as control/status and data registers for the peripherals. interrupt requests are generated by the peripherals based on specific events which occur during their operation (e.g. operation complete, error, etc.). for interfacing with external hardware, specific pins of the parallel ports are used, when an input or output function has been selected for a peripheral. during this time, the port pins are controlled by the peripheral (when used as outputs) or by the external hardware which controls the peripheral (when used as inputs). this is called the 'alternate (input or output) function' of a port pin, in contrast to its function as a general purpose io pin.
       user ? s manual 2-12 1999-08  peripheral timing internal operation of cpu and peripherals is based on the cpu clock (  cpu ). the on-chip oscillator derives the cpu clock from the crystal or from the external clock signal. the clock signal which is gated to the peripherals is independent from the clock signal which feeds the cpu. during idle mode the cpu ? s clock is stopped while the peripherals continue their operation. peripheral sfrs may be accessed by the cpu once per state. when an sfr is written to by software in the same state where it is also to be modified by the peripheral, the software write operation has priority. further details on peripheral timing are included in the specific sections about each peripheral. programming hints access to sfrs all sfrs reside in data page 3 of the memory space. the following addressing mechanisms allow to access the sfrs:  indirect or direct addressing with 16-bit (mem) addresses must guarantee that the used data page pointer (dpp0...dpp3) selects data page 3.  accesses via the peripheral event controller ( pec ) use the srcpx and dstpx pointers instead of the data page pointers.  short 8-bit (reg) addresses to the standard sfr area do not use the data page pointers but directly access the registers within this 512 byte area.  short 8-bit (reg) addresses to the extended esfr area require switching to the 512 byte extended sfr area. this is done via the extension instructions extr, extp(r), exts(r). byte write operations to word wide sfrs via indirect or direct 16-bit (mem) addressing or byte transfers via the pec force zeros in the non-addressed byte. byte write operations via short 8-bit (reg) addressing can only access the low byte of an sfr and force zeros in the high byte. it is therefore recommended, to use the bit field instructions (bfldl and bfldh) to write to any number of bits in either byte of an sfr without disturbing the non-addressed byte and the unselected bits. reserved bits some of the bits which are contained in the c161pi's sfrs are marked as 'reserved'. user software should never write '1's to reserved bits. these bits are currently not implemented and may be used in future products to invoke new functions. in this case, the active state for these functions will be '1', and the inactive state will be '0'. therefore writing only ? 0 ? s to reserved locations provides portability of the current software to future devices. after read accesses reserved bits should be ignored or masked out.
       user ? s manual 2-13 1999-08  serial channels serial communication with other microcontrollers, processors, terminals or external peripheral components is provided by two serial interfaces with different functionality, an asynchronous/synchronous serial channel ( asc0 ) and a high-speed synchronous serial channel ( ssc ). the asc0 is upward compatible with the serial ports of the siemens 8-bit microcontroller families and supports full-duplex asynchronous communication at up to 780 kbaud and half-duplex synchronous communication at up to 3.1 mbaud @ 25 mhz cpu clock. a dedicated baud rate generator allows to set up all standard baud rates without oscillator tuning. for transmission, reception and error handling 4 separate interrupt vectors are provided. in asynchronous mode, 8- or 9-bit data frames are transmitted or received, preceded by a start bit and terminated by one or two stop bits. for multiprocessor communication, a mechanism to distinguish address from data bytes has been included (8-bit data plus wake up bit mode). in synchronous mode, the asc0 transmits or receives bytes (8 bits) synchronously to a shift clock which is generated by the asc0. the asc0 always shifts the lsb first. a loop back option is available for testing purposes. a number of optional hardware error detection capabilities has been included to increase the reliability of data transfers. a parity bit can automatically be generated on transmission or be checked on reception. framing error detection allows to recognize data frames with missing stop bits. an overrun error will be generated, if the last character received has not been read out of the receive buffer register at the time the reception of a new character is complete. the ssc supports full-duplex synchronous communication at up to 6.25 mbaud @ 25 mhz cpu clock. it may be configured so it interfaces with serially linked peripheral components. a dedicated baud rate generator allows to set up all standard baud rates without oscillator tuning. for transmission, reception and error handling 3 separate interrupt vectors are provided. the ssc transmits or receives characters of 2...16 bits length synchronously to a shift clock which can be generated by the ssc (master mode) or by an external master (slave mode). the ssc can start shifting with the lsb or with the msb and allows the selection of shifting and latching clock edges as well as the clock polarity. a number of optional hardware error detection capabilities has been included to increase the reliability of data transfers. transmit and receive error supervise the correct handling of the data buffer. phase and baudrate error detect incorrect serial data.
       user ? s manual 2-14 1999-08  the on-chip i 2 c bus module the integrated i 2 c module handles the transmission and reception of frames over the two-line i 2 c bus in accordance with the i 2 c bus specification. the on-chip i 2 c module can receive and transmit data using 7-bit or 10-bit addressing and it can operate in slave mode, in master mode or in multi-master mode. several physical interfaces (port pins) can be established under software control. data can be transferred at speeds up to 400 kbit/sec. two interrupt nodes dedicated to the i 2 c module allow efficient interrupt service and also support operation via pec transfers. note: the port pins associated with the i 2 c interfaces feature open drain drivers only, as required by the i 2 c specification. a/d converter for analog signal measurement, an 8-bit a/d converter with 4 multiplexed input channels and a sample and hold circuit has been integrated on-chip. it uses the method of successive approximation. the sample time (for loading the capacitors) and the conversion time is programmable and can so be adjusted to the external circuitry. overrun error detection is provided for the conversion result register (addat): an interrupt request will be generated when the result of a previous conversion has not been read from the result register at the time the next conversion is complete. for applications which require less analog input channels, the remaining channel inputs can be used as digital input port pins. the a/d converter of the c161pi supports two different conversion modes. in the standard single channel conversion mode, the analog level on a specified channel is sampled once and converted to a digital result. in the single channel continuous mode, the analog level on a specified channel is repeatedly sampled and converted without software intervention. the peripheral event controller (pec) may be used to automatically store the conversion results into a table in memory for later evaluation, without requiring the overhead of entering and exiting interrupt routines for each data transfer.
       user ? s manual 2-15 1999-08  general purpose timer (gpt) unit the gpt units represent a very flexible multifunctional timer/counter structure which may be used for many different time related tasks such as event timing and counting, pulse width and duty cycle measurements, pulse generation, or pulse multiplication. each timer may operate independently in a number of different modes, or may be concatenated with another timer of the same module. each timer can be configured individually for one of four basic modes of operation, which are timer, gated timer, counter mode and incremental interface mode (gpt1 timers). in timer mode the input clock for a timer is derived from the internal cpu clock divided by a programmable prescaler, while counter mode allows a timer to be clocked in reference to external events (via txin). pulse width or duty cycle measurement is supported in gated timer mode where the operation of a timer is controlled by the ? gate ? level on its external input pin txin. in incremental interface mode the gpt1 timers can be directly connected to the incremental position sensor signals a and b via the respective inputs txin and txeud. direction and count signals are internally derived from these two input signals, so the contents of timer tx corresponds to the sensor position. the third position sensor signal top0 can be connected to an interrupt input. the count direction (up/down) for each timer is programmable by software or may additionally be altered dynamically by an external signal (txeud) to facilitate e.g. position tracking. the core timers t3 and t6 have output toggle latches (txotl) which change their state on each timer over-flow/underflow. the state of these latches may be used internally to concatenate the core timers with the respective auxiliary timers resulting in 32/33-bit timers/counters for measuring long time periods with high resolution. various reload or capture functions can be selected to reload timers or capture a timer ? s contents triggered by an external signal or a selectable transition of toggle latch txotl. the maximum resolution of the timers in module gpt1 is 8 cpu clock cycles (= 16 tcl). with their maximum resolution of 4 cpu clock cycles (= 8 tcl) the gpt2 timers provide precise event control and time measurement.
       user ? s manual 2-16 1999-08  watchdog timer the watchdog timer represents one of the fail-safe mechanisms which have been implemented to prevent the controller from malfunctioning for longer periods of time. the watchdog timer is always enabled after a reset of the chip, and can only be disabled in the time interval until the einit (end of initialization) instruction has been executed. thus, the chip ? s start-up procedure is always monitored. the software has to be designed to service the watchdog timer before it overflows. if, due to hardware or software related failures, the software fails to do so, the watchdog timer overflows and generates an internal hardware reset and pulls the rstout pin low in order to allow external hardware components to reset. the watchdog timer is a 16-bit timer, clocked with the cpu clock divided either by 2 or by 128. the high byte of the watchdog timer register can be set to a prespecified reload value (stored in wdtrel) in order to allow further variation of the monitored time interval. each time it is serviced by the application software, the high byte of the watchdog timer is reloaded. thus, time intervals between 21 s and 335 ms can be monitored (@ 25 mhz). the default watchdog timer interval after reset is 5.2 ms (@ 25 mhz). real time clock the c161pi contains a real time clock (rtc) which serves for different purposes:  system clock to determine the current time and date, even during idle mode and power down mode (optionally)  cyclic time based interrupt, e.g. to provide a system time tick independent of the cpu frequency without loading the general purpose timers, or to wake up regularly from idle mode.  48-bit timer for long term measurements, the maximum usable timespan is more than 100 years. the rtc module consists of a chain of 3 divider blocks, a fixed 8:1 divider, the reloadable 16-bit timer t14 and the 32-bit rtc timer (accessible via registers rtch and rtcl). both timers count up.
       user ? s manual 2-17 1999-08  parallel ports the c161pi provides up to 76 io lines which are organized into six input/output ports and one input port. all port lines are bit-addressable, and all input/output lines are individually (bit-wise) programmable as inputs or outputs via direction registers. the io ports are true bidirectional ports which are switched to high impedance state when configured as inputs. the output drivers of three io ports can be configured (pin by pin) for push/pull operation or open-drain operation via control registers. during the internal reset, all port pins are configured as inputs. all port lines have programmable alternate input or output functions associated with them. port0 and port1 may be used as address and data lines when accessing external memory, while port 4 outputs the additional segment address bits a22/19/ 17...a16 in systems where segmentation is used to access more than 64 kbytes of memory. port 6 provides i 2 c bus lines and the chip select signals cs4 ...cs0 . port 2 accepts the fast external interrupt inputs. port 3 includes alternate functions of timers, serial interfaces, the optional bus control signal bhe and the system clock output (clkout). port 5 is used for timer control signals and for the analog inputs to the a/d converter. all port lines that are not used for these alternate functions may be used as general purpose io lines.
       user ? s manual 2-18 1999-08  2.4 power management features the known basic power reduction modes (idle and power down) are enhanced by a number of additional power management features (see below). these features can be combined to reduce the controller ? s power consumption to the respective application ? s possible minimum.  flexible clock generation  flexible peripheral management (peripherals can be dis/unabled separately or in groups)  periodic wakeup from idle mode via rtc timer the listed features provide effective means to realize standby conditions for the system with an optimum balance between power reduction (i.e. standby time) and peripheral operation (i.e. system functionality). flexible clock generation the flexible clock generation system combines a variety of improved mechanisms (partly user controllable) to provide the c161pi modules with clock signals. this is especially important in power sensitive modes like standby operation. the power optimized oscillator generally reduces the amount of power which is consumed in order to generate the clock signal within the c161pi. the clock system efficiently controls the amount of power which is consumed in order to distribute the clock signal within the c161pi. slowdown operation is achieved by dividing the oscillator clock by a programmable factor (1...32) resulting in a low frequency device operation which significantly reduces the overall power consumption. flexible peripheral management the flexible peripheral management provides a mechanism to enable and disable each peripheral module separately. in each situation (e.g. several system operating modes, standby, etc.) only those peripherals may be kept running which are required for the respective functionality. all others can be switched off. it also allows the operation control of whole groups of peripherals including the power required for generating and distributing their clock input signal. other peripherals may remain active, e.g. in order to maintain communication channels. the registers of separately disabled peripherals (not within a disabled group) can still be accessed.
       user ? s manual 2-19 1999-08  periodic wakeup from idle mode periodic wakeup from idle mode combines the drastically reduced power consumption in idle mode (in conjunction with the additional power management features) with a high level of system availability. external signals and events can be scanned (at a lower rate) by periodically activating the cpu and selected peripherals which then return to powersave mode after a short time. this greatly reduces the system ? s average power consumption.
       user ? s manual 2-20 1999-08  2.5 protected bits the c161pi provides a special mechanism to protect bits which can be modified by the on-chip hardware from being changed unintentionally by software accesses to related bits (see also chapter ? the central processing unit ? ). the following bits are protected: = 45 protected bits. table 2-1 c161pi protected bits register bit name notes t2ic, t3ic, t4ic t2ir, t3ir, t4ir gpt1 timer interrupt request flags t5ic, t6ic t5ir, t6ir gpt2 timer interrupt request flags cric crir gpt2 caprel interrupt request flag t3con, t6con t3otl, t6otl gptx timer output toggle latches s0tic, s0tbic s0tir, s0tbir asc0 transmit(buffer) interrupt request flags s0ric, s0eic s0rir, s0eir asc0 receive/error interrupt request flags s0con s0ren asc0 receiver enable flag ssctic, sscric ssctir, sscrir ssc transmit/receive interrupt request flags ssceic ssceir ssc error interrupt request flag ssccon sscbsy ssc busy flag ssccon sscbe, sscpe ssc error flags ssccon sscre, sscte ssc error flags adcic, adeic adcir, adeir adc end-of-conv./overrun intr. request flag adcon adst adc start flag request flag cc15ic...cc8ic cc15ir...cc8ir fast external interrupt request flags tfr tfr.15,14,13 class a trap flags tfr tfr.7,3,2,1,0 class b trap flags xp3ic...xp0ic xp3ir...xp0ir x-peripheral interrupt request flags isnc rtcir interrupt node sharing request flag
     user ? s manual 3-1 1999-08  3 memory organization the memory space of the c161pi is configured in a ? von neumann ? architecture. this means that code and data are accessed within the same linear address space. all of the physically separated memory areas, including internal rom/flash/otp (where integrated), internal ram, the internal special function register areas (sfrs and esfrs), the address areas for integrated xbus peripherals and external memory are mapped into one common address space. the c161pi provides a total addressable memory space of 16 mbytes. this address space is arranged as 256 segments of 64 kbytes each, and each segment is again subdivided into four data pages of 16 kbytes each (see figure below). figure 3-1 address space overview 254...129 255 00 ? 0000 h 0 127 128 64 4 3 2 1 ff ? ffff h 80 ? 0000 h total address space 01 ? ffff h 16 mbyte, segments 255...0 00 ? 0000 h 01 ? ffff h segments 1 and 0 01 ? 0000 h segment 0 segment 1 internal rom area 64 + 64 kbyte 01 ? 8000 h 126...65 63 5 9 8 7 6 11 10 62...12 40 ? 0000 h 0a ? ffff h 08 ? 0000 h 255...2 data page 3 alternate rom area data page 2 8mbyte external addressing. capability 04 ? ffff h
     user ? s manual 3-2 1999-08  most internal memory areas are mapped into segment 0, the system segment. the upper 4 kbyte of segment 0 (00 ? f000 h ...00 ? ffff h ) hold the internal ram and special function register areas (sfr and esfr). the lower 32 kbyte of segment 0 (00 ? 0000 h ...00 ? 7fff h ) may be occupied by a part of the on-chip rom/flash/otp memory and is called the internal rom area. this rom area can be remapped to segment 1 (01 ? 0000 h ...01 ? 7fff h ), to enable external memory access in the lower half of segment 0, or the internal rom may be disabled at all. code and data may be stored in any part of the internal memory areas, except for the sfr blocks, which may be used for control / data, but not for instructions. note: accesses to the internal rom area on romless devices will produce unpredictable results. bytes are stored at even or odd byte addresses. words are stored in ascending memory locations with the low byte at an even byte address being followed by the high byte at the next odd byte address. double words (code only) are stored in ascending memory locations as two subsequent words. single bits are always stored in the specified bit position at a word address. bit position 0 is the least significant bit of the byte at an even byte address, and bit position 15 is the most significant bit of the byte at the next odd byte address. bit addressing is supported for a part of the special function registers, a part of the internal ram and for the general purpose registers. figure 3-2 storage of words, byte and bits in a byte organized memory note: byte units forming a single word or a double word must always be stored within the same physical (internal, external, rom, ram) and organizational (page, segment) memory area.
     user ? s manual 3-3 1999-08  3.1 internal rom area the c161pi may reserve an address area of variable size (depending on the version) for on-chip mask-programmable rom/flash/otp memory (organized as x * 32). the lower 32 kbyte of this on-chip memory block are referred to as ? internal rom area ? . internal rom accesses are globally enabled or disabled via bit romen in register syscon. this bit is set during reset according to the level on pin ea , or may be altered via software. if enabled, the internal rom area occupies the lower 32 kbyte of either segment 0 or segment 1 (alternate rom area). this mapping is controlled by bit roms1 in register syscon. note: the size of the internal rom area is independent of the size of the actual implemented program memory. also devices with less than 32 kbyte of program memory or with no program memory at all will have this 32 kbyte area occupied, if the program memory is enabled. devices with a larger program memory provide the mapping option only for the internal rom area. devices with a program memory size above 32 kbyte expand the rom area from the middle of segment 1, i.e. starting at address 01 ? 8000 h . the internal program memory can be used for both code (instructions) and data (constants, tables, etc.) storage. code fetches are always made on even byte addresses. the highest possible code storage location in the internal program memory is either xx ? xxfe h for single word instructions, or xx ? xxfc h for double word instructions. the respective location must contain a branch instruction (unconditional), because sequential boundary crossing from internal program memory to external memory is not supported and causes erroneous results. any word and byte data read accesses may use the indirect or long 16-bit addressing modes. there is no short addressing mode for internal rom operands. any word data access is made to an even byte address. the highest possible word data storage location in the internal program memory is xx ? xxfe h . for pec data transfers the internal program memory can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. the internal program memory is not provided for single bit storage, and therefore it is not bit addressable. note: the ? x ? in the locations above depend on the available program memory and on the mapping. the internal program memory may be enabled, disabled or mapped into segment 0 or segment 1 under software control. chapter ? system programming ? shows how to do this and reminds of the precautions that must be taken in order to prevent the system from crashing.
     user ? s manual 3-4 1999-08  3.2 internal ram and sfr area the ram/sfr area is located within data page 3 and provides access to the internal ram (iram, organized as x*16) and to two 512 byte blocks of special function registers (sfrs). the c161pi provides 1 kbyte of iram. figure 3-3 system memory map ext. memory 00 ? ffff h 00 ? 8000 h 00 ? e000 h 00 ? c000 h 00 ? f000 h ext. memory data page 3 data page 2 iram/sfr xram/x-per. xram 00 ? e000 h 00 ? ffff h 00 ? f000 h sfr area esfr area iram reserved 00 ? ed00 h note: new xbus peripherals will be preferably placed into the shaded areas, which now access external memory (bus cycles executed). 00 ? fa00 h reserved i 2 c reserved 00 ? e7ff h
     user ? s manual 3-5 1999-08  note: the upper 256 bytes of sfr area, esfr area and internal ram are bit- addressable (see hashed blocks in the figure above). code accesses are always made on even byte addresses. the highest possible code storage location in the internal ram is either 00 ? fdfe h for single word instructions or 00 ? fdfc h for double word instructions. the respective location must contain a branch instruction (unconditional), because sequential boundary crossing from internal ram to the sfr area is not supported and causes erroneous results. any word and byte data in the internal ram can be accessed via indirect or long 16-bit addressing modes, if the selected dpp register points to data page 3. any word data access is made on an even byte address. the highest possible word data storage location in the internal ram is 00 ? fdfe h . for pec data transfers, the internal ram can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. the upper 256 byte of the internal ram (00 ? fd00 h through 00 ? fdff h ) and the gprs of the current bank are provided for single bit storage, and thus they are bit addressable. system stack the system stack may be defined within the internal ram. the size of the system stack is controlled by bitfield stksz in register syscon (see table below). for all system stack operations the on-chip ram is accessed via the stack pointer (sp) register. the stack grows downward from higher towards lower ram address locations. only word accesses are supported to the system stack. a stack overflow (stkov) and a stack underflow (stkun) register are provided to control the lower and upper limits of the selected stack area. these two stack boundary registers can be used not only for protection against data destruction, but also allow to implement a circular stack with hardware supported system stack flushing and filling (except for option ? 111 ? ). the technique of implementing this circular stack is described in chapter ? system programming ? . table 3-1 system stack size encoding stack size (words) internal ram addresses (words) 0 0 0 b 256 00 ? fbfe h ...00 ? fa00 h (default after reset) 0 0 1 b 128 00 ? fbfe h ...00 ? fb00 h 0 1 0 b 64 00 ? fbfe h ...00 ? fb80 h 0 1 1 b 32 00 ? fbfe h ...00 ? fbc0 h 1 0 0 b --- reserved. do not use this combination. 1 0 1 b --- reserved. do not use this combination. 1 1 0 b --- reserved. do not use this combination. 1 1 1 b 512 00 ? fdfe h ...00 ? fa00 h (note: no circular stack)
     user ? s manual 3-6 1999-08  general purpose registers the general purpose registers (gprs) use a block of 16 consecutive words within the internal ram. the context pointer (cp) register determines the base address of the currently active register bank. this register bank may consist of up to 16 word-gprs (r0, r1, ..., r15) and/or of up to 16 byte-gprs (rl0, rh0, ..., rl7, rh7). the sixteen byte-gprs are mapped onto the first eight word-gprs (see table below). in contrast to the system stack, a register bank grows from lower towards higher address locations and occupies a maximum space of 32 byte. the gprs are accessed via short 2-, 4-, or 8-bit addressing modes using the context pointer (cp) register as base address (independent of the current dpp register contents). additionally, each bit in the currently active register bank can be accessed individually. the c161pi supports fast register bank (context) switching. multiple register banks can physically exist within the internal ram at the same time. only the register bank selected by the context pointer register (cp) is active at a given time, however. selecting a new active register bank is simply done by updating the cp register. a particular switch context (scxt) instruction performs register bank switching and an automatic saving of the previous context. the number of implemented register banks (arbitrary sizes) is only limited by the size of the available internal ram. details on using, switching and overlapping register banks are described in chapter ? system programming ? . table 3-2 mapping of general purpose registers to ram addresses internal ram address byte registers word register + 1e h --- r15 + 1c h --- r14 + 1a h --- r13 + 18 h --- r12 + 16 h --- r11 + 14 h --- r10 + 12 h --- r9 + 10 h --- r8 + 0e h rh7 rl7 r7 + 0c h rh6 rl6 r6 + 0a h rh5 rl5 r5 + 08 h rh4 rl4 r4 + 06 h rh3 rl3 r3 + 04 h rh2 rl2 r2 + 02 h rh1 rl1 r1 + 00 h rh0 rl0 r0
     user ? s manual 3-7 1999-08  pec source and destination pointers the 16 word locations in the internal ram from 00 ? fce0 h to 00 ? fcfe h (just below the bit-addressable section) are provided as source and destination address pointers for data transfers on the eight pec channels. each channel uses a pair of pointers stored in two subsequent word locations with the source pointer (srcpx) on the lower and the destination pointer (dstpx) on the higher word address (x = 7...0). figure 3-4 location of the pec pointers whenever a pec data transfer is performed, the pair of source and destination pointers, which is selected by the specified pec channel number, is accessed independent of the current dpp register contents and also the locations referred to by these pointers are accessed independent of the current dpp register contents. if a pec channel is not used, the corresponding pointer locations area available and can be used for word or byte data storage. for more details about the use of the source and destination pointers for pec data transfers see section ? interrupt and trap functions ? . 00 ? fce2 00 ? fce0 h h srcp0 dstp0 00 ? f5fe 00 ? f600 mcd03903 h h destination 00 ? fcfc pointers and h pec source srcp7 00 ? fcfe h dstp7 internal 00 ? fce0 00 ? fcde ram h h 00 ? fcfe 00 ? fd00 h h
     user ? s manual 3-8 1999-08  special function registers the functions of the cpu, the bus interface, the io ports and the on-chip peripherals of the c161pi are controlled via a number of so-called special function registers (sfrs). these sfrs are arranged within two areas of 512 byte size each. the first register block, the sfr area, is located in the 512 bytes above the internal ram (00 ? ffff h ...00 ? fe00 h ), the second register block, the extended sfr (esfr) area, is located in the 512 bytes below the internal ram (00 ? f1ff h ...00 ? f000 h ). special function registers can be addressed via indirect and long 16-bit addressing modes. using an 8-bit offset together with an implicit base address allows to address word sfrs and their respective low bytes. however, this does not work for the respective high bytes! note: writing to any byte of an sfr causes the non-addressed complementary byte to be cleared! the upper half of each register block is bit-addressable, so the respective control/status bits can directly be modified or checked using bit addressing. when accessing registers in the esfr area using 8-bit addresses or direct bit addressing, an extend register (extr) instruction is required before, to switch the short addressing mechanism from the standard sfr area to the extended sfr area. this is not required for 16-bit and indirect addresses. the gprs r15...r0 are duplicated, i.e. they are accessible within both register blocks via short 2-, 4- or 8-bit addresses without switching. esfr_switch_example: extr #4 ;switch to esfr area for next 4 instr. mov odp2, #data16 ;odp2 uses 8-bit reg addressing bfldl dp6, #mask, #data8 ;bit addressing for bit fields bset dp1h.7 ;bit addressing for single bits mov t8rel, r1 ;t8rel uses 16-bit mem address, ;r1 is duplicated into the esfr space ;(extr is not required for this access) ;---- ;----------------- ;the scope of the extr #4 instruction... ;...ends here! mov t8rel, r1 ;t8rel uses 16-bit mem address, ;r1 is accessed via the sfr space in order to minimize the use of the extr instructions the esfr area mostly holds registers which are mainly required for initialization and mode selection. registers that need to be accessed frequently are allocated to the standard sfr area, wherever possible. note: the tools are equipped to monitor accesses to the esfr area and will automatically insert extr instructions, or issue a warning in case of missing or excessive extr instructions.
     user ? s manual 3-9 1999-08  3.3 the on-chip xram the c161pi provides access to 2kbyte of on-chip extension ram. the xram is located within data page 3 (organized as 1k*16 ). as the xram is connected to the internal xbus it is accessed like external memory, however, no external bus cycles are executed for these accesses. xram accesses are globally enabled or disabled via bit xpen in register syscon. this bit is cleared after reset and may be set via software during the initialization to allow accesses to the on-chip xram. when the xram is disabled (default after reset) all accesses to the xram area are mapped to external locations. the xram may be used for both code (instructions) and data (variables, user stack, tables, etc.) storage. code fetches are always made on even byte addresses. the highest possible code storage location in the xram is either 00 ? e7fe h for single word instructions, or 00 ? e7fc h for double word instructions. the respective location must contain a branch instruction (unconditional), because sequential boundary crossing from xram to external memory is not supported and causes erroneous results. any word and byte data read accesses may use the indirect or long 16-bit addressing modes. there is no short addressing mode for xram operands. any word data access is made to an even byte address. the highest possible word data storage location in the xram is 00 ? e7fe h . for pec data transfers the xram can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. note: as the xram appears like external memory it cannot be used for the c161pi ? s system stack or register banks. the xram is not provided for single bit storage and therefore is not bit addressable. the on-chip xram is accessed with the following bus cycles:  normal ale  no cycle time waitstates (no ready control)  no tristate time waitstate  no read/write delay  16-bit demultiplexed bus cycles (4 tcl). even if the xram is used like external memory it does not occupy busconx/ addrselx registers but rather is selected via additional dedicated xbcon/xadrs registers. these registers are mask-programmed and are not user accessible. with these registers the address area 00 ? e000 h to 00 ? e7ff h is reserved for xram accesses.
     user ? s manual 3-10 1999-08  xram access via external masters when bit xper-share in register syscon is set the on-chip xram of the c161pi can be accessed by an external master during hold mode via the c161pi ? s bus interface. these external accesses must use the same configuration as internally programmed, i.e. demultiplexed bus, 4 tcl minimum access cycle time. no waitstates are required. note: the configuration in register syscon cannot be changed after the execution of the einit instruction.
     user ? s manual 3-11 1999-08  3.4 external memory space the c161pi is capable of using an address space of up to 16 mbyte. only parts of this address space are occupied by internal memory areas. all addresses which are not used for on-chip memory (rom/flash/otp or ram) or for registers may reference external memory locations. this external memory is accessed via the c161pi ? s external bus interface. four memory bank sizes are supported:  non-segmented mode: 64 kbyte with a15...a0 on port0 or port1  2-bit segmented mode: 256 kbyte with a17...a16 on port 4 and a15...a0 on port0 or port1  4-bit segmented mode: 1 mbyte with a19...a16 on port 4 and a15...a0 on port0 or port1  7-bit segmented mode: 8 mbyte with a22...a16 on port 4 and a15...a0 on port0 or port1 each bank can be directly addressed via the address bus, while the programmable chip select signals can be used to select various memory banks. the c161pi also supports four different bus types :  multiplexed 16-bit bus with address and data on port0 (default after reset)  multiplexed 8-bit bus with address and data on port0/p0l  demultiplexed 16-bit bus with address on port1 and data on port0  demultiplexed 8-bit bus with address on port1 and data on p0l memory model and bus mode are selected during reset by pin ea and port0 pins. for further details about the external bus configuration and control please refer to chapter "the external bus interface". external word and byte data can only be accessed via indirect or long 16-bit addressing modes using one of the four dpp registers. there is no short addressing mode for external operands. any word data access is made to an even byte address. for pec data transfers the external memory in segment 0 can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. the external memory is not provided for single bit storage and therefore it is not bit addressable.
     user ? s manual 3-12 1999-08  3.5 crossing memory boundaries the address space of the c161pi is implicitly divided into equally sized blocks of different granularity and into logical memory areas. crossing the boundaries between these blocks (code or data) or areas requires special attention to ensure that the controller executes the desired operations. memory areas are partitions of the address space that represent different kinds of memory (if provided at all). these memory areas are the internal ram/sfr area, the internal rom/flash/otp (if available), the on-chip x-peripherals (if integrated) and the external memory. accessing subsequent data locations that belong to different memory areas is no problem. however, when executing code , the different memory areas must be switched explicitly via branch instructions. sequential boundary crossing is not supported and leads to erroneous results. note: changing from the external memory area to the internal ram/sfr area takes place within segment 0. segments are contiguous blocks of 64 kbyte each. they are referenced via the code segment pointer csp for code fetches and via an explicit segment number for data accesses overriding the standard dpp scheme. during code fetching segments are not changed automatically, but rather must be switched explicitly. the instructions jmps, calls and rets will do this. in larger sequential programs make sure that the highest used code location of a segment contains an unconditional branch instruction to the respective following segment, to prevent the prefetcher from trying to leave the current segment. data pages are contiguous blocks of 16 kbyte each. they are referenced via the data page pointers dpp3...0 and via an explicit data page number for data accesses overriding the standard dpp scheme. each dpp register can select one of the possible 1024 data pages. the dpp register that is used for the current access is selected via the two upper bits of the 16-bit data address. subsequent 16-bit data addresses that cross the 16 kbyte data page boundaries therefore will use different data page pointers, while the physical locations need not be subsequent within memory.
     user ? s manual 4-1 1999-08  4 the central processing unit (cpu) basic tasks of the cpu are to fetch and decode instructions, to supply operands for the arithmetic and logic unit (alu), to perform operations on these operands in the alu, and to store the previously calculated results. as the cpu is the main engine of the c161pi controller, it is also affected by certain actions of the peripheral subsystem. since a four stage pipeline is implemented in the c161pi, up to four instructions can be processed in parallel. most instructions of the c161pi are executed in one machine cycle (2 cpu clock periods) due to this parallelism. this chapter describes how the pipeline works for sequential and branch instructions in general, and which hardware provisions have been made to speed the execution of jump instructions in particular. the general instruction timing is described including standard and exceptional timing. while internal memory accesses are normally performed by the cpu itself, external peripheral or memory accesses are performed by a particular on-chip external bus controller (ebc), which is automatically invoked by the cpu whenever a code or data address refers to the external address space. figure 4-1 cpu block diagram
     user ? s manual 4-2 1999-08  if possible, the cpu continues operating while an external memory access is in progress. if external data are required but are not yet available, or if a new external memory access is requested by the cpu, before a previous access has been completed, the cpu will be held by the ebc until the request can be satisfied. the ebc is described in a dedicated chapter. the on-chip peripheral units of the c161pi work nearly independent of the cpu with a separate clock generator. data and control information is interchanged between the cpu and these peripherals via special function registers (sfrs). whenever peripherals need a non-deterministic cpu action, an on-chip interrupt controller compares all pending peripheral service requests against each other and prioritizes one of them. if the priority of the current cpu operation is lower than the priority of the selected peripheral request, an interrupt will occur. basically, there are two types of interrupt processing:  standard interrupt processing forces the cpu to save the current program status and the return address on the stack before branching to the interrupt vector jump table.  pec interrupt processing steals just one machine cycle from the current cpu activity to perform a single data transfer via the on-chip peripheral event controller (pec). system errors detected during program execution (socalled hardware traps) or an external non-maskable interrupt are also processed as standard interrupts with a very high priority. in contrast to other on-chip peripherals, there is a closer conjunction between the watchdog timer and the cpu. if enabled, the watchdog timer expects to be serviced by the cpu within a programmable period of time, otherwise it will reset the chip. thus, the watchdog timer is able to prevent the cpu from going totally astray when executing erroneous code. after reset, the watchdog timer starts counting automatically, but it can be disabled via software, if desired. beside its normal operation there are the following particular cpu states:  reset state: any reset (hardware, software, watchdog) forces the cpu into a predefined active state.  idle state: the clock signal to the cpu itself is switched off, while the clocks for the on-chip peripherals keep running.  power down state: all of the on-chip clocks are switched off (rtc clock selectable), all inputs are disregarded.  sleep state: all of the on-chip clocks are switched off (rtc clock selectable), external interrupt inputs are enabled.
     user ? s manual 4-3 1999-08  a transition into an active cpu state is forced by an interrupt (if being in idle or sleep mode) or by a reset (if being in power down mode). the idle, sleep, power down, and reset states can be entered by particular c161pi system control instructions. a set of special function registers is dedicated to the functions of the cpu core:  general system configuration: syscon (rp0h)  cpu status indication and control: psw  code access control: ip, csp  data paging control: dpp0, dpp1, dpp2, dpp3  gprs access control: cp  system stack access control: sp, stkun, stkov  multiply and divide support: mdl, mdh, mdc  alu constants support: zeros, ones
     user ? s manual 4-4 1999-08  4.1 instruction pipelining the instruction pipeline of the c161pi partitiones instruction processing into four stages of which each one has its individual task: 1st ?>fetch: in this stage the instruction selected by the instruction pointer (ip) and the code segment pointer (csp) is fetched from either the internal rom, internal ram, or external memory. 2nd ?>decode: in this stage the instructions are decoded and, if required, the operand addresses are calculated and the respective operands are fetched. for all instructions, which implicitly access the system stack, the sp register is either decremented or incremented, as specified. for branch instructions the instruction pointer and the code segment pointer are updated with the desired branch target address (provided that the branch is taken). 3rd ?>execute: in this stage an operation is performed on the previously fetched operands in the alu. additionally, the condition flags in the psw register are updated as specified by the instruction. all explicit writes to the sfr memory space and all auto- increment or auto-decrement writes to gprs used as indirect address pointers are performed during the execute stage of an instruction, too. 4th ?>write back: in this stage all external operands and the remaining operands within the internal ram space are written back. a particularity of the c161pi are the so-called injected instructions. these injected instructions are generated internally by the machine to provide the time needed to process instructions, which cannot be processed within one machine cycle. they are automatically injected into the decode stage of the pipeline, and then they pass through the remaining stages like every standard instruction. program interrupts are performed by means of injected instructions, too. although these internally injected instructions will not be noticed in reality, they are introduced here to ease the explanation of the pipeline in the following. sequential instruction processing each single instruction has to pass through each of the four pipeline stages regardless of whether all possible stage operations are really performed or not. since passing through one pipeline stage takes at least one machine cycle, any isolated instruction takes at least four machine cycles to be completed. pipelining, however, allows parallel (i.e. simultaneous) processing of up to four instructions. thus, most of the instructions seem to be processed during one machine cycle as soon as the pipeline has been filled once after reset (see figure below). instruction pipelining increases the average instruction throughput considered over a certain period of time. in the following, any execution time specification of an instruction always refers to the average execution time due to pipelined parallel instruction processing.
     user ? s manual 4-5 1999-08  figure 4-2 sequential instruction pipelining standard branch instruction processing instruction pipelining helps to speed sequential program processing. in the case that a branch is taken, the instruction which has already been fetched providently is mostly not the instruction which must be decoded next. thus, at least one additional machine cycle is normally required to fetch the branch target instruction. this extra machine cycle is provided by means of an injected instruction (see figure below). figure 4-3 standard branch instruction pipelining if a conditional branch is not taken, there is no deviation from the sequential program flow, and thus no extra time is required. in this case the instruction after the branch instruction will enter the decode stage of the pipeline at the beginning of the next machine cycle after decode of the conditional branch instruction. 1 machine cycle fetch i 2 i 1 i 3 i 2 i 1 i 4 i 3 i 2 i 1 i 6 i 5 i 4 i 3 i 5 i 4 i 3 i 2 i 1 decode execute writeback time 1 machine cycle fetch i n+2 branch i n . . . i target (i inject ) branch i n i target+1 i target (i inject ) branch i target+3 i target+2 i target+1 i target i target+2 i target+1 i target (i inject ) branch i n . . . . . . decode execute writeback time injection
     user ? s manual 4-6 1999-08  cache jump instruction processing the c161pi incorporates a jump cache to optimize conditional jumps, which are processed repeatedly within a loop. whenever a jump on cache is taken, the extra time to fetch the branch target instruction can be saved and thus the corresponding cache jump instruction in most cases takes only one machine cycle. this performance is achieved by the following mechanism: whenever a cache jump instruction passes through the decode stage of the pipeline for the first time (and provided that the jump condition is met), the jump target instruction is fetched as usual, causing a time delay of one machine cycle. in contrast to standard branch instructions, however, the target instruction of a cache jump instruction (jmpa, jmpr, jb, jbc, jnb, jnbs) is additionally stored in the cache after having been fetched. after each repeatedly following execution of the same cache jump instruction, the jump target instruction is not fetched from progam memory but taken from the cache and immediatly injected into the decode stage of the pipeline (see figure below). a time saving jump on cache is always taken after the second and any further occurrence of the same cache jump instruction, unless an instruction which, has the fundamental capability of changing the csp register contents (jmps, calls, rets, trap, reti), or any standard interrupt has been processed during the period of time between two following occurrences of the same cache jump instruction. figure 4-4 cache jump instruction pipelining i n+2 cache jmp i n . . . i target+1 i target cache jmp i n i target+2 i target+1 i target cache jmp i n+2 cache jmp i n . . . i target (i inject ) cache jmp i n i target+1 i target (i inject ) cache jmp 1 machine cycle fetch decode execute writeback 1st loop iteration injection injection of cached target instruction repeated loop iteration
     user ? s manual 4-7 1999-08  4.2 particular pipeline effects since up to four different instructions are processed simultaneously, additional hardware has been spent in the c161pi to consider all causal dependencies which may exist on instructions in different pipeline stages without a loss of performance. this extra hardware (i.e. for ? forwarding ? operand read and write values) resolves most of the possible conflicts (e.g. multiple usage of buses) in a time optimized way and thus avoids that the pipeline becomes noticeable for the user in most cases. however, there are some very rare cases, where the circumstance that the c161pi is a pipelined machine requires attention by the programmer. in these cases the delays caused by pipeline conflicts can be used for other instructions in order to optimize performance. ? context pointer updating an instruction, which calculates a physical gpr operand address via the cp register, is mostly not capable of using a new cp value, which is to be updated by an immediately preceding instruction. thus, to make sure that the new cp value is used, at least one instruction must be inserted between a cp-changing and a subsequent gpr-using instruction, as shown in the following example: i n :scxt cp,#0fc00h ;select a new context i n+1 :.... ;must not be an instruction using a gpr i n+2 :mov r0,#datax ;write to gpr 0 in the new context ? data page pointer updating an instruction, which calculates a physical operand address via a particular dppn (n=0 to 3) register, is mostly not capable of using a new dppn register value, which is to be updated by an immediately preceding instruction. thus, to make sure that the new dppn register value is used, at least one instruction must be inserted between a dppn- changing instruction and a subsequent instruction which implicitly uses dppn via a long or indirect addressing mode, as shown in the following example: i n :mov dpp0,#4 ;select data page 4 via dpp0 i n+1 :.... ;must not be an instruction using dpp0 i n+2 :mov dpp0:0000h,r1;move contents of r1 to address location 01?0000 h ;(in data page 4) supposed segment. is enabled
     user ? s manual 4-8 1999-08  ? explicit stack pointer updating none of the ret, reti, rets, retp or pop instructions is capable of correctly using a new sp register value, which is to be updated by an immediately preceding instruction. thus, in order to use the new sp register value without erroneously performed stack accesses, at least one instruction must be inserted between an explicitly sp-writing and any subsequent of the just mentioned implicitly sp-using instructions, as shown in the following example: i n :mov sp,#0fa40h ;select a new top of stack i n+1 :.... ;must not be an instruction popping operands ;from the system stack i n+2 :pop r0 ;pop word value from new top of stack into r0 note: conflicts with instructions writing to the stack (push, call, scxt) are solved internally by the cpu logic. ? controlling interrupts software modifications (implicit or explicit) of the psw are done in the execute phase of the respective instructions. in order to maintain fast interrupt responses, however, the current interrupt prioritization round does not consider these changes, i.e. an interrupt request may be acknowledged after the instruction that disables interrupts via ien or ilvl or after the following instructions. timecritical instruction sequences therefore should not begin directly after the instruction disabling interrupts, as shown in the following examples: interrupts_off: bclr ien ;globally disable interrupts ;non-critical instruction ;begin of uninterruptable critical sequence . . . ;end of uninterruptable critical sequence interrupts_on: bset ien ;globally re-enable interrupts critical_sequence: atomic #3 ;immediately block interrupts bclr ien ;globally disable interrupts . . . ;here is the uninterruptable sequence bset ien ;globally re-enable interrupts note: the described delay of 1 instruction also applies for enabling the interrupts system i.e. no interrupt requests are acknowledged until the instruction following the enabling instruction.
     user ? s manual 4-9 1999-08  ? external memory access sequences the effect described here will only become noticeable, when watching the external memory access sequences on the external bus (e.g. by means of a logic analyzer). different pipeline stages can simultaneously put a request on the external bus controller (ebc). the sequence of instructions processed by the cpu may diverge from the sequence of the corresponding external memory accesses performed by the ebc, due to the predefined priority of external memory accesses: 1st write data 2nd fetch code 3rd read data. ? initialization of port pins modifications of the direction of port pins (input or output) become effective only after the instruction following the modifying instruction. as bit instructions (bset, bclr) use internal read-modify-write sequences accessing the whole port, instructions modifying the port direction should be followed by an instruction that does not access the same port (see example below). port_init_wrong: bset dp3.13 ;change direction of p3.13 to output bset p3.9 ;p3.13 is still input, ;rd-mod-wr reads pin p3.13 port_init_right: bset dp3.13 ;change direction of p3.13 to output nop ;any instruction not accessing port 3 bset p3.9 ;p3.13 is now output, ;rd-mod-wr reads p3.13 ? s output latch ? changing the system configuration the instruction following an instruction that changes the system configuration via register syscon (e.g. the mapping of the internal rom, segmentation, stack size) cannot use the new resources (e.g. rom or stack). in these cases an instruction that does not access these resources should be inserted. code accesses to the new rom area are only possible after an absolute branch to this area. note: as a rule, instructions that change rom mapping should be executed from internal ram or external memory.
     user ? s manual 4-10 1999-08  ? buscon/addrsel the instruction following an instruction that changes the properties of an external address area cannot access operands within the new area. in these cases an instruction that does not access this address area should be inserted. code accesses to the new address area should be made after an absolute branch to this area. note: as a rule, instructions that change external bus properties should not be executed from the respective external memory area. ? timing instruction pipelining reduces the average instruction processing time in a wide scale (from four to one machine cycles, mostly). however, there are some rare cases, where a particular pipeline situation causes the processing time for a single instruction to be extended either by a half or by one machine cycle. although this additional time represents only a tiny part of the total program execution time, it might be of interest to avoid these pipeline-caused time delays in time critical program modules. besides a general execution time description, the following section provides some hints on how to optimize time-critical program parts with regard to such pipeline-caused timing particularities.
     user ? s manual 4-11 1999-08  4.3 bit-handling and bit-protection the c161pi provides several mechanisms to manipulate bits. these mechanisms either manipulate software flags within the internal ram, control on-chip peripherals via control bits in their respective sfrs or control io functions via port pins. the instructions bset, bclr, band, bor, bxor, bmov, bmovn explicitly set or clear specific bits. the instructions bfldl and bfldh allow to manipulate up to 8 bits of a specific byte at one time. the instructions jbc and jnbs implicitly clear or set the specified bit when the jump is taken. the instructions jb and jnb (also conditional jump instructions that refer to flags) evaluate the specified bit to determine if the jump is to be taken. note: bit operations on undefined bit locations will always read a bit value of ? 0 ? , while the write access will not effect the respective bit location. all instructions that manipulate single bits or bit groups internally use a read-modify-write sequence that accesses the whole word, which contains the specified bit(s). this method has several consequences:  bits can only be modified within the internal address areas, i.e. internal ram and sfrs. external locations cannot be used with bit instructions. the upper 256 bytes of the sfr area, the esfr area and the internal ram are bit- addressable (see chapter ? memory organization ? ), i.e. those register bits located within the respective sections can be directly manipulated using bit instructions. the other sfrs must be accessed byte/word wise. note: all gprs are bit-addressable independent of the allocation of the register bank via the context pointer cp. even gprs which are allocated to not bit-addressable ram locations provide this feature.  the read-modify-write approach may be critical with hardware-effected bits. in these cases the hardware may change specific bits while the read-modify-write operation is in progress, where the writeback would overwrite the new bit value generated by the hardware. the solution is either the implemented hardware protection (see below) or realized through special programming (see ? particular pipeline effects ? ). protected bits are not changed during the read-modify-write sequence, i.e. when hardware sets e.g. an interrupt request flag between the read and the write of the read- modify-write sequence. the hardware protection logic guarantees that only the intended bit(s) is/are effected by the write-back operation. note: if a conflict occurs between a bit manipulation generated by hardware and an intended software access the software access has priority and determines the final value of the respective bit. a summary of the protected bits implemented in the c161pi can be found at the end of chapter ? architectural overview ? .
     user ? s manual 4-12 1999-08  4.4 instruction state times basically, the time to execute an instruction depends on where the instruction is fetched from, and where possible operands are read from or written to. the fastest processing mode of the c161pi is to execute a program fetched from the internal code memory. in that case most of the instructions can be processed within just one machine cycle, which is also the general minimum execution time. all external memory accesses are performed by the c161pi ? s on-chip external bus controller (ebc), which works in parallel with the cpu. this section summarizes the execution times in a very condensed way. a detailled description of the execution times for the various instructions and the specific exceptions can be found in the ? c16x family instruction set manual ? . the table below shows the minimum execution times required to process a c161pi instruction fetched from the internal code memory, the internal ram or from external memory. these execution times apply to most of the c161pi instructions - except some of the branches, the multiplication, the division and a special move instruction. in case of internal rom program execution there is no execution time dependency on the instruction length except for some special branch situations. the numbers in the table are in units of cpu clock cycles and assume no waitstates. execution from the internal ram provides flexibility in terms of loadable and modifyable code on the account of execution time. execution from external memory strongly depends on the selected bus mode and the programming of the bus cycles (waitstates). table 4-1 minimum execution times instruction fetch word operand access memory area word instruction doubleword instruction read from write to internal code memory 2 2 2 --- internal ram 6 8 0/1 0 16-bit demux bus 2 4 2 2 16-bit mux bus 3 6 3 3 8-bit demux bus 4 8 4 4 8-bit mux bus 6 12 6 6
     user ? s manual 4-13 1999-08  the operand and instruction accesses listed below can extend the execution time of an instruction:  internal code memory operand reads (same for byte and word operand reads)  internal ram operand reads via indirect addressing modes  internal sfr operand reads immediately after writing  external operand reads  external operand writes  jumps to non-aligned double word instructions in the internal rom space  testing branch conditions immediately after psw writes 4.5 cpu special function registers the core cpu requires a set of special function registers (sfrs) to maintain the system state information, to supply the alu with register-addressable constants and to control system and bus configuration, multiply and divide alu operations, code memory segmentation, data memory paging, and accesses to the general purpose registers and the system stack. the access mechanism for these sfrs in the cpu core is identical to the access mechanism for any other sfr. since all sfrs can simply be controlled by means of any instruction, which is capable of addressing the sfr memory space, a lot of flexibility has been gained, without the need to create a set of system-specific instructions. note, however, that there are user access restrictions for some of the cpu core sfrs to ensure proper processor operations. the instruction pointer ip and code segment pointer csp cannot be accessed directly at all. they can only be changed indirectly via branch instructions. the psw, sp, and mdc registers can be modified not only explicitly by the programmer, but also implicitly by the cpu during normal instruction processing. note that any explicit write request (via software) to an sfr supersedes a simultaneous modification by hardware of the same register. note: any write operation to a single byte of an sfr clears the non-addressed complementary byte within the specified sfr. non-implemented (reserved) sfr bits cannot be modified, and will always supply a read value of ? 0 ? .
     user ? s manual 4-14 1999-08  the system configuration register syscon this bit-addressable register provides general system configuration and control functions. the reset value for register syscon depends on the state of the port0 pins during reset (see hardware effectable bits). syscon system control register sfr (ff12 h /89 h ) reset value: 0xx0 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 stksz rom s1 sgt dis rom en byt dis clk en wr cfg cs cfg - owd dis bd rst en xpen visi- ble xper sha- re rw rw rw rwh rwh rw rwh rw - rwh rw rw rw rw bit function xper-share xbus peripheral share mode control 0: external accesses to xbus peripherals are disabled 1: xbus peripherals are accessible via the ext. bus during hold mode visible visible mode control 0: accesses to xbus peripherals are done internally 1: xbus peripheral accesses are made visible on the external pins xpen xbus peripheral enable bit 0: accesses to the on-chip x-peripherals and their functions are disabled 1: the on-chip x-peripherals are enabled and can be accessed bdrsten bidirectional reset enable bit 0: pin rstin is an input only. 1: pin rstin is pulled low during the internal reset sequence after any reset. owddis oscillator watchdog disable bit 0: the on-chip oscillator watchdog is enabled and active. 1: the on-chip oscillator watchdog is disabled and the cpu clock is always fed from the oscillator input. cscfg chip select configuration control 0: latched cs mode. the cs signals are latched internally and driven to the (enabled) port pins synchronously. 1: unlatched cs mode. the cs signals are directly derived from the address and driven to the (enabled) port pins. wrcfg write configuration control (set according to pin p0h.0 during reset) 0: pins wr and bhe retain their normal function 1: pin wr acts as wrl , pin bhe acts as wrh
     user ? s manual 4-15 1999-08  note: register syscon cannot be changed after execution of the einit instruction. the function of bits xper-share, visible, wrcfg, bytdis, romen and roms1 is described in more detail in chapter ? the external bus controller ? . clken system clock output enable (clkout) 0: clkout disabled: pin may be used for general purpose io or for signal fout 1: clkout enabled: pin outputs the system clock signal bytdis disable/enable control for pin bhe (set according to data bus width) 0: pin bhe enabled 1: pin bhe disabled, pin may be used for general purpose io romen internal rom enable (set according to pin ea during reset) 0: internal program memory disabled, accesses to the rom area use the external bus 1: internal program memory enabled sgtdis segmentation disable/enable control 0: segmentation enabled (csp is saved/restored during interrupt entry/exit) 1: segmentation disabled (only ip is saved/restored) roms1 internal rom mapping 0: internal rom area mapped to segment 0 (00 ? 0000 h ...00 ? 7fff h ) 1: internal rom area mapped to segment 1 (01 ? 0000 h ...01 ? 7fff h ) stksz system stack size selects the size of the system stack (in the internal ram) from 32 to 512 words bit function
     user ? s manual 4-16 1999-08  system clock output enable (clken) the system clock output function is enabled by setting bit clken in register syscon to ? 1 ? . if enabled, port pin p3.15 takes on its alternate function as clkout output pin. the clock output is a 50 % duty cycle clock (except for direct drive operation where clkout reflects the clock input signal, and for slowdown operation where clkout mirrors the cpu clock signal) whose frequency equals the cpu operating frequency ( f out = f cpu ). note: the output driver of port pin p3.15 is switched on automatically, when the clkout function is enabled. the port direction bit is disregarded. after reset, the clock output function is disabled (clken = ? 0 ? ). in emulation mode the clkout function is enabled automatically. segmentation disable/enable control (sgtdis) bit sgtdis allows to select either the segmented or non-segmented memory mode. in non-segmented memory mode (sgtdis= ? 1 ? ) it is assumed that the code address space is restricted to 64 kbytes (segment 0) and thus 16 bits are sufficient to represent all code addresses. for implicit stack operations (call or ret) the csp register is totally ignored and only the ip is saved to and restored from the stack. in segmented memory mode (sgtdis= ? 0 ? ) it is assumed that the whole address space is available for instructions. for implicit stack operations (call or ret) the csp register and the ip are saved to and restored from the stack. after reset the segmented memory mode is selected. note: bit sgtdis controls if the csp register is pushed onto the system stack in addition to the ip register before an interrupt service routine is entered, and it is repopped when the interrupt service routine is left again. system stack size (stksz) this bitfield defines the size of the physical system stack, which is located in the internal ram of the c161pi. an area of 32...256 words or all of the internal ram may be dedicated to the system stack. a so-called ? circular stack ? mechanism allows to use a bigger virtual stack than this dedicated ram area. these techniques as well as the encoding of bitfield stksz are described in more detail in chapter ? system programming ? .
     user ? s manual 4-17 1999-08  the processor status word psw this bit-addressable register reflects the current state of the microcontroller. two groups of bits represent the current alu status, and the current cpu interrupt status. a separate bit (usr0) within register psw is provided as a general purpose user flag. alu status (n, c, v, z, e, mulip) the condition flags (n, c, v, z, e) within the psw indicate the alu status due to the last recently performed alu operation. they are set by most of the instructions due to specific rules, which depend on the alu or data movement operation performed by an instruction. psw program status word sfr (ff10 h /88 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ilvl ien - - - - usr0 mul ip ezvcn rwh rw - - - - rw rwh rwh rwh rwh rwh rwh bit function n negative result set, when the result of an alu operation is negative. ccarry flag set, when the result of an alu operation produces a carry bit. v overflow result set, when the result of an alu operation produces an overflow. z zero flag set, when the result of an alu operation is zero. e end of table flag set, when the source operand of an instruction is 8000 h or 80 h . mulip multiplication/division in progress 0: there is no multiplication/division in progress. 1: a multiplication/division has been interrupted. usr0 user general purpose flag may be used by the application software. ilvl, ien interrupt and ebc control fields define the response to interrupt requests. (described in section ? interrupt and trap functions ? )
     user ? s manual 4-18 1999-08  after execution of an instruction which explicitly updates the psw register, the condition flags cannot be interpreted as described in the following, because any explicit write to the psw register supersedes the condition flag values, which are implicitly generated by the cpu. explicitly reading the psw register supplies a read value which represents the state of the psw register after execution of the immediately preceding instruction. note: after reset, all of the alu status bits are cleared.  n-flag: for most of the alu operations, the n-flag is set to ? 1 ? , if the most significant bit of the result contains a ? 1 ? , otherwise it is cleared. in the case of integer operations the n-flag can be interpreted as the sign bit of the result (negative: n= ? 1 ? , positive: n= ? 0 ? ). negative numbers are always represented as the 2's complement of the corresponding positive number. the range of signed numbers extends from ' ? 8000 h ' to '+7fff h ' for the word data type, or from ' ? 80 h ' to '+7f h ' for the byte data type.for boolean bit operations with only one operand the n-flag represents the previous state of the specified bit. for boolean bit operations with two operands the n-flag represents the logical xoring of the two specified bits.  c-flag: after an addition the c-flag indicates that a carry from the most significant bit of the specified word or byte data type has been generated. after a subtraction or a comparison the c-flag indicates a borrow, which represents the logical negation of a carry for the addition. this means that the c-flag is set to ? 1 ? , if no carry from the most significant bit of the specified word or byte data type has been generated during a subtraction, which is performed internally by the alu as a 2 ? s complement addition, and the c-flag is cleared when this complement addition caused a carry. the c-flag is always cleared for logical, multiply and divide alu operations, because these operations cannot cause a carry anyhow. for shift and rotate operations the c-flag represents the value of the bit shifted out last. if a shift count of zero is specified, the c-flag will be cleared. the c-flag is also cleared for a prioritize alu operation, because a ? 1 ? is never shifted out of the msb during the normalization of an operand. for boolean bit operations with only one operand the c-flag is always cleared. for boolean bit operations with two operands the c-flag represents the logical anding of the two specified bits.  v-flag: for addition, subtraction and 2 ? s complementation the v-flag is always set to ? 1 ? , if the result overflows the maximum range of signed numbers, which are representable by either 16 bits for word operations (' ? 8000 h ' to '+7fff h '), or by 8 bits for byte operations (' ? 80 h ' to '+7f h '), otherwise the v-flag is cleared. note that the result of an integer addition, integer subtraction, or 2's complement is not valid, if the v-flag indicates an arithmetic overflow.
     user ? s manual 4-19 1999-08  for multiplication and division the v-flag is set to ? 1 ? , if the result cannot be represented in a word data type, otherwise it is cleared. note that a division by zero will always cause an overflow. in contrast to the result of a division, the result of a multiplication is valid regardless of whether the v-flag is set to ? 1 ? or not. since logical alu operations cannot produce an invalid result, the v-flag is cleared by these operations. the v-flag is also used as ? sticky bit ? for rotate right and shift right operations. with only using the c-flag, a rounding error caused by a shift right operation can be estimated up to a quantity of one half of the lsb of the result. in conjunction with the v-flag, the c-flag allows evaluating the rounding error with a finer resolution (see table below). for boolean bit operations with only one operand the v-flag is always cleared. for boolean bit operations with two operands the v-flag represents the logical oring of the two specified bits.  z-flag: the z-flag is normally set to ? 1 ? , if the result of an alu operation equals zero, otherwise it is cleared. for the addition and subtraction with carry the z-flag is only set to ? 1 ? , if the z-flag already contains a ? 1 ? and the result of the current alu operation additionally equals zero. this mechanism is provided for the support of multiple precision calculations. for boolean bit operations with only one operand the z-flag represents the logical negation of the previous state of the specified bit. for boolean bit operations with two operands the z-flag represents the logical noring of the two specified bits. for the prioritize alu operation the z-flag indicates, if the second operand was zero or not.  e-flag: the e-flag can be altered by instructions, which perform alu or data movement operations. the e-flag is cleared by those instructions which cannot be reasonably used for table search operations. in all other cases the e-flag is set depending on the value of the source operand to signify whether the end of a search table is reached or not. if the value of the source operand of an instruction equals the lowest negative number, which is representable by the data format of the corresponding instruction ( ? 8000 h ? for the word data type, or ? 80 h ? for the byte data type), the e-flag is set to ? 1 ? , otherwise it is cleared. table 4-2 shift right rounding error evaluation c-flag v-flag rounding error quantity 0 0 1 1 0 1 0 1 - no rounding error - 0 < rounding error < 1 / 2 lsb rounding error = 1 / 2 lsb rounding error > 1 / 2 lsb
     user ? s manual 4-20 1999-08   mulip-flag: the mulip-flag will be set to ? 1 ? by hardware upon the entrance into an interrupt service routine, when a multiply or divide alu operation was interrupted before completion. depending on the state of the mulip bit, the hardware decides whether a multiplication or division must be continued or not after the end of an interrupt service. the mulip bit is overwritten with the contents of the stacked mulip-flag when the return-from-interrupt-instruction (reti) is executed. this normally means that the mulip-flag is cleared again after that. note: the mulip flag is a part of the task environment! when the interrupting service routine does not return to the interrupted multiply/divide instruction ( i.e. in case of a task scheduler that switches between independent tasks), the mulip flag must be saved as part of the task environment and must be updated accordingly for the new task before this task is entered. cpu interrupt status (ien, ilvl) the interrupt enable bit allows to globally enable (ien= ? 1 ? ) or disable (ien= ? 0 ? ) interrupts. the four-bit interrupt level field (ilvl) specifies the priority of the current cpu activity. the interrupt level is updated by hardware upon entry into an interrupt service routine, but it can also be modified via software to prevent other interrupts from being acknowledged. in case an interrupt level '15' has been assigned to the cpu, it has the highest possible priority, and thus the current cpu operation cannot be interrupted except by hardware traps or external non-maskable interrupts. for details please refer to chapter ? interrupt and trap functions ? . after reset all interrupts are globally disabled, and the lowest priority (ilvl=0) is assigned to the initial cpu activity.
     user ? s manual 4-21 1999-08  the instruction pointer ip this register determines the 16-bit intra-segment address of the currently fetched instruction within the code segment selected by the csp register. the ip register is not mapped into the c161pi ? s address space, and thus it is not directly accessable by the programmer. the ip can, however, be modified indirectly via the stack by means of a return instruction. the ip register is implicitly updated by the cpu for branch instructions and after instruction fetch operations. the code segment pointer csp this non-bit addressable register selects the code segment being used at run-time to access instructions. the lower 8 bits of register csp select one of up to 256 segments of 64 kbytes each, while the upper 8 bits are reserved for future use. ip instruction pointer - - - (- - - -/- -) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ip (r)(w)h bit function ip specifies the intra segment offset, from where the current instruction is to be fetched. ip refers to the current segment . csp code segment pointer sfr (fe08 h /04 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -------- segnr - - - - - - - - rh bit function segnr segment number specifies the code segment, from where the current instruction is to be fetched. segnr is ignored, when segmentation is disabled.
     user ? s manual 4-22 1999-08  code memory addresses are generated by directly extending the 16-bit contents of the ip register by the contents of the csp register as shown in the figure below. in case of the segmented memory mode the selected number of segment address bits (via bitfield salsel) of register csp is output on the respective segment address pins of port 4 for all external code accesses. for non-segmented memory mode or single chip mode the content of this register is not significant, because all code acccesses are automatically restricted to segment 0. note: the csp register can only be read but not written by data operations. it is, however, modified either directly by means of the jmps and calls instructions, or indirectly via the stack by means of the rets and reti instructions. upon the acceptance of an interrupt or the execution of a software trap instruction, the csp register is automatically set to zero. figure 4-5 addressing via the code segment pointer note: when segmentation is disabled, the ip value is used directly as the 16-bit address.
     user ? s manual 4-23 1999-08  the data page pointers dpp0, dpp1, dpp2, dpp3 these four non-bit addressable registers select up to four different data pages being active simultaneously at run-time. the lower 10 bits of each dpp register select one of the 1024 possible 16-kbyte data pages while the upper 6 bits are reserved for future use. the dpp registers allow to access the entire memory space in pages of 16 kbytes each. dpp0 data page pointer 0 sfr (fe00 h /00 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------ dpp0pn - - - - - - rw dpp1 data page pointer 1 sfr (fe02 h /01 h ) reset value: 0001 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------ dpp1pn - - - - - - rw dpp2 data page pointer 2 sfr (fe04 h /02 h ) reset value: 0002 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------ dpp2pn - - - - - - rw dpp3 data page pointer 3 sfr (fe06 h /03 h ) reset value: 0003 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------ dpp3pn - - - - - - rw bit function dppxpn data page number of dppx specifies the data page selected via dppx. only the least significant two bits of dppx are significant, when segmentation is disabled.
     user ? s manual 4-24 1999-08  the dpp registers are implicitly used, whenever data accesses to any memory location are made via indirect or direct long 16-bit addressing modes (except for override accesses via extended instructions and pec data transfers). after reset, the data page pointers are initialized in a way that all indirect or direct long 16-bit addresses result in identical 18-bit addresses. this allows to access data pages 3...0 within segment 0 as shown in the figure below. if the user does not want to use any data paging, no further action is required. data paging is performed by concatenating the lower 14 bits of an indirect or direct long 16-bit address with the contents of the dpp register selected by the upper two bits of the 16-bit address. the contents of the selected dpp register specify one of the 1024 possible data pages. this data page base address together with the 14-bit page offset forms the physical 24-bit address (selectable part is driven to the address pins). in case of non-segmented memory mode, only the two least significant bits of the implicitly selected dpp register are used to generate the physical address. thus, extreme care should be taken when changing the content of a dpp register, if a non- segmented memory model is selected, because otherwise unexpected results could occur. in case of the segmented memory mode the selected number of segment address bits (via bitfield salsel) of the respective dpp register is output on the respective segment address pins of port 4 for all external data accesses. a dpp register can be updated via any instruction, which is capable of modifying an sfr. note: due to the internal instruction pipeline, a new dpp value is not yet usable for the operand address calculation of the instruction immediately following the instruction updating the dpp register. figure 4-6 addressing via the data page pointers after reset or with segmentation disabled the dpp registers select data pages 3...0. all of the internal memory is accessible in these cases.
     user ? s manual 4-25 1999-08  the context pointer cp this non-bit addressable register is used to select the current register context. this means that the cp register value determines the address of the first general purpose register (gpr) within the current register bank of up to 16 wordwide and/or bytewide gprs. note: it is the user ? s responsibility that the physical gpr address specified via cp register plus short gpr address must always be an internal ram location. if this condition is not met, unexpected results may occur.  do not set cp below the iram start address, i.e. 00 ? fa00 h /00 ? f600 h /00 ? f200 h (referring to an iram size of 1/2/3 kbyte)  do not set cp above 00 ? fdfe h  be careful using the upper gprs with cp above 00 ? fde0 h the cp register can be updated via any instruction which is capable of modifying an sfr. note: due to the internal instruction pipeline, a new cp value is not yet usable for gpr address calculations of the instruction immediately following the instruction updating the cp register. the switch context instruction (scxt) allows to save the content of register cp on the stack and updating it with a new value in just one machine cycle. cp context pointer sfr (fe10 h /08 h ) reset value: fc00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1111 cp 0 r r r r rw r bit function cp modifiable portion of register cp specifies the (word) base address of the current register bank. when writing a value to register cp with bits cp.11...cp.9 = ? 000 ? , bits cp.11...cp.10 are set to ? 11 ? by hardware, in all other cases all bits of bit field ? cp ? receive the written value.
     user ? s manual 4-26 1999-08  figure 4-7 register bank selection via register cp
     user ? s manual 4-27 1999-08  several addressing modes use register cp implicitly for address calculations. the addressing modes mentioned below are described in chapter ? instruction set summary ? . short 4-bit gpr addresses (mnemonic: rw or rb) specify an address relative to the memory location specified by the contents of the cp register, i.e. the base of the current register bank. depending on whether a relative word (rw) or byte (rb) gpr address is specified, the short 4-bit gpr address is either multiplied by two or not before it is added to the content of register cp (see figure below). thus, both byte and word gpr accesses are possible in this way. gprs used as indirect address pointers are always accessed wordwise. for some instructions only the first four gprs can be used as indirect address pointers. these gprs are specified via short 2-bit gpr addresses. the respective physical address calculation is identical to that for the short 4-bit gpr addresses. short 8-bit register addresses (mnemonic: reg or bitoff) within a range from f0 h to ff h interpret the four least significant bits as short 4-bit gpr address, while the four most significant bits are ignored. the respective physical gpr address calculation is identical to that for the short 4-bit gpr addresses. for single bit accesses on a gpr, the gpr's word address is calculated as just described, but the position of the bit within the word is specified by a separate additional 4-bit value. figure 4-8 implicit cp use by short gpr addressing modes
     user ? s manual 4-28 1999-08  the stack pointer sp this non-bit addressable register is used to point to the top of the internal system stack (tos). the sp register is pre-decremented whenever data is to be pushed onto the stack, and it is post-incremented whenever data is to be popped from the stack. thus, the system stack grows from higher toward lower memory locations. since the least significant bit of register sp is tied to ? 0 ? and bits 15 through 12 are tied to ? 1 ? by hardware, the sp register can only contain values from f000 h to fffe h . this allows to access a physical stack within the internal ram of the c161pi. a virtual stack (usually bigger) can be realized via software. this mechanism is supported by registers stkov and stkun (see respective descriptions below). the sp register can be updated via any instruction, which is capable of modifying an sfr. note: due to the internal instruction pipeline, a pop or return instruction must not immediately follow an instruction updating the sp register. sp stack pointer register sfr (fe12 h /09 h ) reset value: fc00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1111 sp 0 r r r r rwh r bit function sp modifiable portion of register sp specifies the top of the internal system stack.
     user ? s manual 4-29 1999-08  the stack overflow pointer stkov this non-bit addressable register is compared against the sp register after each operation, which pushes data onto the system stack (e.g. push and call instructions or interrupts) and after each subtraction from the sp register. if the content of the sp register is less than the content of the stkov register, a stack overflow hardware trap will occur. since the least significant bit of register stkov is tied to ? 0 ? and bits 15 through 12 are tied to ? 1 ? by hardware, the stkov register can only contain values from f000 h to fffe h . the stack overflow trap (entered when (sp) < (stkov)) may be used in two different ways:  fatal error indication treats the stack overflow as a system error through the associated trap service routine. under these circumstances data in the bottom of the stack may have been overwritten by the status information stacked upon servicing the stack overflow trap.  automatic system stack flushing allows to use the system stack as a ? stack cache ? for a bigger external user stack. in this case register stkov should be initialized to a value, which represents the desired lowest top of stack address plus 12 according to the selected maximum stack size. this considers the worst case that will occur, when a stack overflow condition is detected just during entry into an interrupt service routine. then, six additional stack word locations are required to push ip, psw, and csp for both the interrupt service routine and the hardware trap service routine. more details about the stack overflow trap service routine and virtual stack management are given in chapter ? system programming ? . stkov stack overflow reg. sfr (fe14 h /0a h ) reset value:fa00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1111 stkov 0 r r r r rw bit function stkov modifiable portion of register stkov specifies the lower limit of the internal system stack.
     user ? s manual 4-30 1999-08  the stack underflow pointer stkun this non-bit addressable register is compared against the sp register after each operation, which pops data from the system stack (e.g. pop and ret instructions) and after each addition to the sp register. if the content of the sp register is greater than the the content of the stkun register, a stack underflow hardware trap will occur. since the least significant bit of register stkun is tied to ? 0 ? and bits 15 through 12 are tied to ? 1 ? by hardware, the stkun register can only contain values from f000 h to fffe h . the stack underflow trap (entered when (sp) > (stkun)) may be used in two different ways:  fatal error indication treats the stack underflow as a system error through the associated trap service routine.  automatic system stack refilling allows to use the system stack as a ? stack cache ? for a bigger external user stack. in this case register stkun should be initialized to a value, which represents the desired highest bottom of stack address. more details about the stack underflow trap service routine and virtual stack management are given in chapter ? system programming ? . scope of stack limit control the stack limit control realized by the register pair stkov and stkun detects cases where the stack pointer sp is moved outside the defined stack area either by add or sub instructions or by push or pop operations (explicit or implicit, i.e. call or ret instructions). this control mechanism is not triggered, i.e. no stack trap is generated, when  the stack pointer sp is directly updated via mov instructions  the limits of the stack area (stkov, stkun) are changed, so that sp is outside of the new limits. stkun stack underflow reg. sfr (fe16 h /0b h ) reset value: fc00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1111 stkun 0 r r r r rw r bit function stkun modifiable portion of register stkun specifies the upper limit of the internal system stack.
     user ? s manual 4-31 1999-08  the multiply/divide high register mdh this register is a part of the 32-bit multiply/divide register, which is implicitly used by the cpu, when it performs a multiplication or a division. after a multiplication, this non-bit addressable register represents the high order 16 bits of the 32-bit result. for long divisions, the mdh register must be loaded with the high order 16 bits of the 32-bit dividend before the division is started. after any division, register mdh represents the 16-bit remainder. whenever this register is updated via software, the multiply/divide register in use (mdriu) flag in the multiply/divide control register (mdc) is set to ? 1 ? . when a multiplication or division is interrupted before its completion and when a new multiply or divide operation is to be performed within the interrupt service routine, register mdh must be saved along with registers mdl and mdc to avoid erroneous results. a detailed description of how to use the mdh register for programming multiply and divide algorithms can be found in chapter ? system programming ? . mdh multiply/divide high reg. sfr (fe0c h /06 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 mdh rwh bit function mdh specifies the high order 16 bits of the 32-bit multiply and divide reg. md.
     user ? s manual 4-32 1999-08  the multiply/divide low register mdl this register is a part of the 32-bit multiply/divide register, which is implicitly used by the cpu, when it performs a multiplication or a division. after a multiplication, this non-bit addressable register represents the low order 16 bits of the 32-bit result. for long divisions, the mdl register must be loaded with the low order 16 bits of the 32-bit dividend before the division is started. after any division, register mdl represents the 16- bit quotient. whenever this register is updated via software, the multiply/divide register in use (mdriu) flag in the multiply/divide control register (mdc) is set to ? 1 ? . the mdriu flag is cleared, whenever the mdl register is read via software. when a multiplication or division is interrupted before its completion and when a new multiply or divide operation is to be performed within the interrupt service routine, register mdl must be saved along with registers mdh and mdc to avoid erroneous results. a detailed description of how to use the mdl register for programming multiply and divide algorithms can be found in chapter ? system programming ? . mdl multiply/divide low reg. sfr (fe0e h /07 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 mdl rwh bit function mdl specifies the low order 16 bits of the 32-bit multiply and divide reg. md.
     user ? s manual 4-33 1999-08  the multiply/divide control register mdc this bit addressable 16-bit register is implicitly used by the cpu, when it performs a multiplication or a division. it is used to store the required control information for the corresponding multiply or divide operation. register mdc is updated by hardware during each single cycle of a multiply or divide instruction. when a division or multiplication was interrupted before its completion and the multiply/ divide unit is required, the mdc register must first be saved along with registers mdh and mdl (to be able to restart the interrupted operation later), and then it must be cleared prepare it for the new calculation. after completion of the new division or multiplication, the state of the interrupted multiply or divide operation must be restored. the mdriu flag is the only portion of the mdc register which might be of interest for the user. the remaining portions of the mdc register are reserved for dedicated use by the hardware, and should never be modified by the user in another way than described above. otherwise, a correct continuation of an interrupted multiply or divide operation cannot be guaranteed. a detailed description of how to use the mdc register for programming multiply and divide algorithms can be found in chapter ? system programming ? . mdc multiply/divide control reg. sfr (ff0e h /87 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 --------! !! !! ! mdr iu ! !! !! !! ! - - - - - - - - r(w)h r(w)h r(w)h r(w)h r(w)h r(w)h r(w)h r(w)h bit function mdriu multiply/divide register in use 0: cleared, when register mdl is read via software. 1: set when register mdl or mdh is written via software, or when a multiply or divide instruction is executed. !! internal machine status the multiply/divide unit uses these bits to control internal operations. never modify these bits without saving and restoring register mdc.
     user ? s manual 4-34 1999-08  the constant zeros register zeros all bits of this bit-addressable register are fixed to ? 0 ? by hardware. this register can be read only. register zeros can be used as a register-addressable constant of all zeros, i.e. for bit manipulation or mask generation. it can be accessed via any instruction, which is capable of addressing an sfr. the constant ones register ones all bits of this bit-addressable register are fixed to ? 1 ? by hardware. this register can be read only. register ones can be used as a register-addressable constant of all ones, i.e. for bit manipulation or mask generation. it can be accessed via any instruction, which is capable of addressing an sfr. zeros zeros register sfr (ff1c h /8e h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0000000000000000 r r r r r r r r r r r r r r r r ones ones register sfr (ff1e h /8f h ) reset value: ffff h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1111111111111111 r r r r r r r r r r r r r r r r
  !
!"    user ? s manual 5-1 1999-08  5 interrupt and trap functions the architecture of the c161pi supports several mechanisms for fast and flexible response to service requests that can be generated from various sources internal or external to the microcontroller. these mechanisms include: normal interrupt processing the cpu temporarily suspends the current program execution and branches to an interrupt service routine in order to service an interrupt requesting device. the current program status (ip, psw, in segmentation mode also csp) is saved on the internal system stack. a prioritization scheme with 16 priority levels allows the user to specify the order in which multiple interrupt requests are to be handled. interrupt processing via the peripheral event controller (pec) a faster alternative to normal software controlled interrupt processing is servicing an interrupt requesting device with the c161pi ? s integrated peripheral event controller (pec). triggered by an interrupt request, the pec performs a single word or byte data transfer between any two locations in segment 0 (data pages 0 through 3) through one of eight programmable pec service channels. during a pec transfer the normal program execution of the cpu is halted for just 1 instruction cycle. no internal program status information needs to be saved. the same prioritization scheme is used for pec service as for normal interrupt processing. pec transfers share the 2 highest priority levels. trap functions trap functions are activated in response to special conditions that occur during the execution of instructions. a trap can also be caused externally by the non-maskable interrupt pin nmi . several hardware trap functions are provided for handling erroneous conditions and exceptions that arise during the execution of an instruction. hardware traps always have highest priority and cause immediate system reaction. the software trap function is invoked by the trap instruction, which generates a software interrupt for a specified interrupt vector. for all types of traps the current program status is saved on the system stack. external interrupt processing although the c161pi does not provide dedicated interrupt pins, it allows to connect external interrupt sources and provides several mechanisms to react on external events, including standard inputs, non-maskable interrupts and fast external interrupts. these interrupt functions are alternate port functions, except for the non-maskable interrupt and the reset input.
  !
!"    user ? s manual 5-2 1999-08  5.1 interrupt system structure the c161pi provides 27 separate interrupt nodes that may be assigned to 16 priority levels. in order to support modular and consistent software design techniques, most sources of an interrupt or pec request are supplied with a separate interrupt control register and interrupt vector. the control register contains the interrupt request flag, the interrupt enable bit, and the interrupt priority of the associated source. each source request is then activated by one specific event, depending on the selected operating mode of the respective device. for efficient usage of the resources also multi-source interrupt nodes are incorporated. these nodes can be activated by several source requests, e.g. as different kinds of errors in the serial interfaces. however, specific status flags which identify the type of error are implemented in the serial channels ? control registers. additional sharing of interrupt nodes is supported via the interrupt subnode control register isnc (see description below). the c161pi provides a vectored interrupt system. in this system specific vector locations in the memory space are reserved for the reset, trap, and interrupt service functions. whenever a request occurs, the cpu branches to the location that is associated with the respective interrupt source. this allows direct identification of the source that caused the request. the only exceptions are the class b hardware traps, which all share the same interrupt vector. the status flags in the trap flag register (tfr) can then be used to determine which exception caused the trap. for the special software trap instruction, the vector address is specified by the operand field of the instruction, which is a seven bit trap number. the reserved vector locations build a jump table in the low end of the c161pi ? s address space (segment 0). the jump table is made up of the appropriate jump instructions that transfer control to the interrupt or trap service routines, which may be located anywhere within the address space. the entries of the jump table are located at the lowest addresses in code segment 0 of the address space. each entry occupies 2 words, except for the reset vector and the hardware trap vectors, which occupy 4 or 8 words. the table below lists all sources that are capable of requesting interrupt or pec service in the c161pi, the associated interrupt vectors, their locations and the associated trap numbers. it also lists the mnemonics of the affected interrupt request flags and their corresponding interrupt enable flags. the mnemonics are composed of a part that specifies the respective source, followed by a part that specifies their function (ir=interrupt request flag, ie=interrupt enable flag). note: each entry of the interrupt vector table provides room for two word instructions or one doubleword instruction. the respective vector location results from multiplying the trap number by 4 (4 bytes per entry). all interrupt nodes that are currently not used by their associated modules or are not connected to a module in the actual derivative may be used to generate software controlled interrupt requests by setting the respective ir flag.
  !
!"    user ? s manual 5-3 1999-08  table 5-1 c161pi interrupt nodes and vectors source of interrupt or pec service request request flag enable flag interrupt vector vector location trap number fast external interrupt 0 cc8ir cc8ie cc8int 00 ? 0060 h 18 h / 24 d fast external interrupt 1 cc9ir cc9ie cc9int 00 ? 0064 h 19 h / 25 d fast external interrupt 2 cc10ir cc10ie cc10int 00 ? 0068 h 1a h / 26 d fast external interrupt 3 cc11ir cc11ie cc11int 00 ? 006c h 1b h / 27 d fast external interrupt 4 cc12ir cc12ie cc12int 00 ? 0070 h 1c h / 28 d fast external interrupt 5 cc13ir cc13ie cc13int 00 ? 0074 h 1d h / 29 d fast external interrupt 6 cc14ir cc14ie cc14int 00 ? 0078 h 1e h / 30 d fast external interrupt 7 cc15ir cc15ie cc15int 00 ? 007c h 1f h / 31 d gpt1 timer 2 t2ir t2ie t2int 00 ? 0088 h 22 h / 34 d gpt1 timer 3 t3ir t3ie t3int 00 ? 008c h 23 h / 35 d gpt1 timer 4 t4ir t4ie t4int 00 ? 0090 h 24 h / 36 d gpt2 timer 5 t5ir t5ie t5int 00 ? 0094 h 25 h / 37 d gpt2 timer 6 t6ir t6ie t6int 00 ? 0098 h 26 h / 38 d gpt2 caprel register crir crie crint 00 ? 009c h 27 h / 39 d a/d conversion complete adcir adcie adcint 00 ? 00a0 h 28 h / 40 d a/d overrun error adeir adeie adeint 00 ? 00a4 h 29 h / 41 d asc0 transmit s0tir s0tie s0tint 00 ? 00a8 h 2a h / 42 d asc0 transmit buffer s0tbir s0tbie s0tbint 00 ? 011c h 47 h / 71 d asc0 receive s0rir s0rie s0rint 00 ? 00ac h 2b h / 43 d asc0 error s0eir s0eie s0eint 00 ? 00b0 h 2c h / 44 d ssc transmit sctir sctie sctint 00 ? 00b4 h 2d h / 45 d ssc receive scrir scrie scrint 00 ? 00b8 h 2e h / 46 d ssc error sceir sceie sceint 00 ? 00bc h 2f h / 47 d i 2 c data transfer event xp0ir xp0ie xp0int 00 ? 0100 h 40 h / 64 d i 2 c protocol event xp1ir xp1ie xp1int 00 ? 0104 h 41 h / 65 d x-peripheral node 2 xp2ir xp2ie xp2int 00 ? 0108 h 42 h / 66 d pll/owd, rtc (via isnc) xp3ir xp3ie xp3int 00 ? 010c h 43 h / 67 d
  !
!"    user ? s manual 5-4 1999-08  the table below lists the vector locations for hardware traps and the corresponding status flags in register tfr. it also lists the priorities of trap service for cases, where more than one trap condition might be detected within the same instruction. after any reset (hardware reset, software reset instruction srst, or reset by watchdog timer overflow) program execution starts at the reset vector at location 00 ? 0000 h . reset conditions have priority over every other system activity and therefore have the highest priority (trap priority iii). software traps may be initiated to any vector location between 00 ? 0000 h and 00 ? 01fc h . a service routine entered via a software trap instruction is always executed on the current cpu priority level which is indicated in bit field ilvl in register psw. this means that routines entered via the software trap instruction can be interrupted by all hardware traps or higher level interrupt requests. table 5-2 hardware trap summary exception condition trap flag trap vector vector location trap number trap prio reset functions: hardware reset software reset watchdog timer overflow reset reset reset 00 ? 0000 h 00 ? 0000 h 00 ? 0000 h 00 h 00 h 00 h iii iii iii class a hardware traps: non-maskable interrupt stack overflow stack underflow nmi stkof stkuf nmitrap stotrap stutrap 00 ? 0008 h 00 ? 0010 h 00 ? 0018 h 02 h 04 h 06 h ii ii ii class b hardware traps: undefined opcode protected instruction fault illegal word operand access illegal instruction access illegal external bus access undopc prtflt illopa illina illbus btrap btrap btrap btrap btrap 00 ? 0028 h 00 ? 0028 h 00 ? 0028 h 00 ? 0028 h 00 ? 0028 h 0a h 0a h 0a h 0a h 0a h i i i i i reserved [2c h ? 3c h ][0b h ? 0f h ] software traps: trap instruction any [00 ? 0000 h ? 00 ? 01fc h ] in steps of 4 h any [00 h ? 7f h ] current cpu priority
  !
!"    user ? s manual 5-5 1999-08  normal interrupt processing and pec service during each instruction cycle one out of all sources which require pec or interrupt processing is selected according to its interrupt priority. this priority of interrupts and pec requests is programmable in two levels. each requesting source can be assigned to a specific priority. a second level (called ? group priority ? ) allows to specify an internal order for simultaneous requests from a group of different sources on the same priority level. at the end of each instruction cycle the one source request with the highest current priority will be determined by the interrupt system. this request will then be serviced, if its priority is higher than the current cpu priority in register psw. interrupt system register description interrupt processing is controlled globally by register psw through a general interrupt enable bit (ien) and the cpu priority field (ilvl). additionally the different interrupt sources are controlled individually by their specific interrupt control registers (...ic). thus, the acceptance of requests by the cpu is determined by both the individual interrupt control registers and the psw. pec services are controlled by the respective peccx register and the source and destination pointers, which specify the task of the respective pec service channel. 5.1.1 interrupt control registers all interrupt control registers are organized identically. the lower 8 bits of an interrupt control register contain the complete interrupt status information of the associated source, which is required during one round of prioritization, the upper 8 bits of the respective register are reserved.. all interrupt control registers are bit-addressable and all bits can be read or written via software. this allows each interrupt source to be programmed or modified with just one instruction. when accessing interrupt control registers through instructions which operate on word data types, their upper 8 bits (15...8) will return zeros, when read, and will discard written data. the layout of the interrupt control registers shown below applies to each xxic register, where xx stands for the mnemonic for the respective source.
  !
!"    user ? s manual 5-6 1999-08  the interrupt request flag is set by hardware whenever a service request from the respective source occurs. it is cleared automatically upon entry into the interrupt service routine or upon a pec service. in the case of pec service the interrupt request flag remains set, if the count field in register peccx of the selected pec channel decrements to zero. this allows a normal cpu interrupt to respond to a completed pec block transfer. note: modifying the interrupt request flag via software causes the same effects as if it had been set or cleared by hardware. xxic interrupt control register (e)sfr (yyyy h /zz h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 xxir xxie ilvl glvl - - - - - - - - rwh rw rw rw bit function glvl group level defines the internal order for simultaneous requests of the same priority. 3: highest group priority 0: lowest group priority ilvl interrupt priority level defines the priority level for the arbitration of requests. f h : highest priority level 0 h : lowest priority level xxie interrupt enable control bit (individually enables/disables a specific source) 0: interrupt request is disabled 1: interrupt request is enabled xxir interrupt request flag 0: no request pending 1: this source has raised an interrupt request
  !
!"    user ? s manual 5-7 1999-08  interrupt priority level and group level the four bits of bit field ilvl specify the priority level of a service request for the arbitration of simultaneous requests. the priority increases with the numerical value of ilvl, so 0000 b is the lowest and 1111 b is the highest priority level. when more than one interrupt request on a specific level gets active at the same time, the values in the respective bit fields glvl are used for second level arbitration to select one request for being serviced. again the group priority increases with the numerical value of glvl, so 00 b is the lowest and 11 b is the highest group priority. note: all interrupt request sources that are enabled and programmed to the same priority level must always be programmed to different group priorities. otherwise an incorrect interrupt vector will be generated. upon entry into the interrupt service routine, the priority level of the source that won the arbitration and who ? s priority level is higher than the current cpu level, is copied into bit field ilvl of register psw after pushing the old psw contents on the stack. the interrupt system of the c161pi allows nesting of up to 15 interrupt service routines of different priority levels (level 0 cannot be arbitrated). interrupt requests that are programmed to priority levels 15 or 14 (ie, ilvl=111x b ) will be serviced by the pec, unless the count field of the associated pecc register contains zero. in this case the request will instead be serviced by normal interrupt processing. interrupt requests that are programmed to priority levels 13 through 1 will always be serviced by normal interrupt processing. note: priority level 0000 b is the default level of the cpu. therefore a request on level 0 will never be serviced, because it can never interrupt the cpu. however, an enabled interrupt request on level 0000 b will terminate the c161pi ? s idle mode and reactivate the cpu. for interrupt requests which are to be serviced by the pec, the associated pec channel number is derived from the respective ilvl (lsb) and glvl (see figure below). so programming a source to priority level 15 (ilvl=1111 b ) selects the pec channel group 7...4, programming a source to priority level 14 (ilvl=1110 b ) selects the pec channel group 3...0. the actual pec channel number is then determined by the group priority field glvl. simultaneous requests for pec channels are prioritized according to the pec channel number, where channel 0 has lowest and channel 8 has highest priority. note: all sources that request pec service must be programmed to different pec channels. otherwise an incorrect pec channel may be activated.
  !
!"    user ? s manual 5-8 1999-08  figure 5-1 priority levels and pec channels the table below shows in a few examples, which action is executed with a given programming of an interrupt control register. note: all requests on levels 13...1 cannot initiate pec transfers. they are always serviced by an interrupt service routine. no pecc register is associated and no count field is checked. table 5-3 interrupt priority examples priority level type of service ilvl glvl count = 00h count 00 h 1 1 1 11 1 cpu interrupt, level 15, group priority 3 pec service, channel 7 1 1 1 11 0 cpu interrupt, level 15, group priority 2 pec service, channel 6 1 1 1 01 0 cpu interrupt, level 14, group priority 2 pec service, channel 2 1 1 0 1 1 0 cpu interrupt, level 13, group priority 2 cpu interrupt, level 13, group priority 2 0 0 0 1 1 1 cpu interrupt, level 1, group priority 3 cpu interrupt, level 1, group priority 3 0 0 0 1 0 0 cpu interrupt, level 1, group priority 0 cpu interrupt, level 1, group priority 0 0 0 0 0 x x no service! no service! interrupt control register pec control pec channel # glvl ilvl
  !
!"    user ? s manual 5-9 1999-08  interrupt control functions in the psw the processor status word (psw) is functionally divided into 2 parts: the lower byte of the psw basically represents the arithmetic status of the cpu, the upper byte of the psw controls the interrupt system of the c161pi and the arbitration mechanism for the external bus interface. note: pipeline effects have to be considered when enabling/disabling interrupt requests via modifications of register psw (see chapter ? the central processing unit ? ). psw   # $ 
sfr (ff10 h /88 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ilvl ien - --- usr 0 mul ip ezvcn rwh rw - - - - rw rwh rwh rwh rwh rwh rwh bit function n, c, v, z, e, mulip, usr0 cpu status flags (described in section ? the central processing unit ? ) define the current status of the cpu (alu, multiplication unit). ien interrupt enable control bit (globally enables/disables interrupt requests) 0: interrupt requests are disabled 1: interrupt requests are enabled ilvl cpu priority level defines the current priority level for the cpu f h : highest priority level 0 h : lowest priority level
  !
!"    user ? s manual 5-10 1999-08  cpu priority ilvl defines the current level for the operation of the cpu. this bit field reflects the priority level of the routine that is currently executed. upon the entry into an interrupt service routine this bit field is updated with the priority level of the request that is being serviced. the psw is saved on the system stack before. the cpu level determines the minimum interrupt priority level that will be serviced. any request on the same or a lower level will not be acknowledged. the current cpu priority level may be adjusted via software to control which interrupt request sources will be acknowledged. pec transfers do not really interrupt the cpu, but rather ? steal ? a single cycle, so pec services do not influence the ilvl field in the psw. hardware traps switch the cpu level to maximum priority (i.e. 15) so no interrupt or pec requests will be acknowledged while an exception trap service routine is executed. note: the trap instruction does not change the cpu level, so software invoked trap service routines may be interrupted by higher requests. interrupt enable bit ien globally enables or disables pec operation and the acceptance of interrupts by the cpu. when ien is cleared, no new interrupt requests are accepted by the cpu. requests that already have entered the pipeline at that time will process, however. when ien is set to '1', all interrupt sources, which have been individually enabled by the interrupt enable bits in their associated control registers, are globally enabled. note: traps are non-maskable and are therefore not affected by the ien bit.
  !
!"    user ? s manual 5-11 1999-08  5.2 operation of the pec channels the c161pi ? s peripheral event controller (pec) provides 8 pec service channels, which move a single byte or word between two locations in segment 0 (data pages 3...0). this is the fastest possible interrupt response and in many cases is sufficient to service the respective peripheral request (e.g. serial channels, etc.). each channel is controlled by a dedicated pec channel counter/control register (peccx) and a pair of pointers for source (srcpx) and destination (dstpx) of the data transfer. the pecc registers control the action that is performed by the respective pec channel. peccx pec ch.x ctrl. reg. sfr (fecy h /6z h , see table) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - - - - - inc bwt count ----- rw rw rw bit function count pec transfer count counts pec transfers and influences the channel ? s action (see table below) bwt byte / word transfer selection 0: transfer a word 1: transfer a byte inc increment control (modification of srcpx or dstpx) 0 0: pointers are not modified 0 1: increment dstpx by 1 or 2 (bwt) 1 0: increment srcpx by 1 or 2 (bwt) 1 1: reserved. do not use this combination. (changed to ? 10 ? by hardware) table 5-4 pec control register addresses register address reg. space register address reg. space pecc0 fec0 h / 60 h sfr pecc4 fec8 h / 64 h sfr pecc1 fec2 h / 61 h sfr pecc5 feca h / 65 h sfr pecc2 fec4 h / 62 h sfr pecc6 fecc h / 66 h sfr pecc3 fec6 h / 63 h sfr pecc7 fece h / 67 h sfr
  !
!"    user ? s manual 5-12 1999-08  byte/word transfer bit bwt controls, if a byte or a word is moved during a pec service cycle. this selection controls the transferred data size and the increment step for the modified pointer. increment control field inc controls, if one of the pec pointers is incremented after the pec transfer. it is not possible to increment both pointers, however. if the pointers are not modified (inc= ? 00 ? ), the respective channel will always move data from the same source to the same destination. note: the reserved combination ? 11 ? is changed to ? 10 ? by hardware. however, it is not recommended to use this combination. the pec transfer count field count controls the action of a respective pec channel, where the content of bit field count at the time the request is activated selects the action. count may allow a specified number of pec transfers, unlimited transfers or no pec service at all. the table below summarizes, how the count field itself, the interrupt requests flag ir and the pec channel action depends on the previous content of count. the pec transfer counter allows to service a specified number of requests by the respective pec channel, and then (when count reaches 00 h ) activate the interrupt service routine, which is associated with the priority level. after each pec transfer the count field is decremented and the request flag is cleared to indicate that the request has been serviced. table 5-5 influence of bitfield count previous count modified count ir after pec service action of pec channel and comments ff h ff h ? 0 ? move a byte / word continuous transfer mode, i.e. count is not modified fe h ..02 h fd h ..01 h ? 0 ? move a byte / word and decrement count 01 h 00 h ? 1 ? move a byte / word leave request flag set, which triggers another request 00 h 00 h ( ? 1 ? ) no action! activate interrupt service routine rather than pec channel.
  !
!"    user ? s manual 5-13 1999-08  continuous transfers are selected by the value ff h in bit field count. in this case count is not modified and the respective pec channel services any request until it is disabled again. when count is decremented from 01 h to 00 h after a transfer, the request flag is not cleared, which generates another request from the same source. when count already contains the value 00 h , the respective pec channel remains idle and the associated interrupt service routine is activated instead. this allows to choose, if a level 15 or 14 request is to be serviced by the pec or by the interrupt service routine. note: pec transfers are only executed, if their priority level is higher than the cpu level, i.e. only pec channels 7...4 are processed, while the cpu executes on level 14. all interrupt request sources that are enabled and programmed for pec service should use different channels. otherwise only one transfer will be performed for all simultaneous requests. when count is decremented to 00 h , and the cpu is to be interrupted, an incorrect interrupt vector will be generated. the source and destination pointers specifiy the locations between which the data is to be moved. a pair of pointers (srcpx and dstpx) is associated with each of the 8 pec channels. these pointers do not reside in specific sfrs, but are mapped into the internal ram of the c161pi just below the bit-addressable area (see figure below). figure 5-2 mapping of pec pointers into the internal ram dstp7 00 ? fcfe h srcp7 00 ? fcfc h dstp6 00 ? fcfa h srcp6 00 ? fcf8 h dstp5 00 ? fcf6 h srcp5 00 ? fcf4 h dstp4 00 ? fcf2 h srcp4 00 ? fcf0 h dstp3 00 ? fcee h srcp3 00 ? fcec h dstp2 00 ? fcea h srcp2 00 ? fce8 h dstp1 00 ? fce6 h srcp1 00 ? fce4 h dstp0 00 ? fce2 h srcp0 00 ? fce0 h
  !
!"    user ? s manual 5-14 1999-08  pec data transfers do not use the data page pointers dpp3...dpp0. the pec source and destination pointers are used as 16-bit intra-segment addresses within segment 0, so data can be transferred between any two locations within the first four data pages 3...0. the pointer locations for inactive pec channels may be used for general data storage. only the required pointers occupy ram locations. note: if word data transfer is selected for a specific pec channel (i.e. bwt= ? 0 ? ), the respective source and destination pointers must both contain a valid word address which points to an even byte boundary. otherwise the illegal word access trap will be invoked, when this channel is used.
  !
!"    user ? s manual 5-15 1999-08  5.3 prioritization of interrupt and pec service requests interrupt and pec service requests from all sources can be enabled, so they are arbitrated and serviced (if they win), or they may be disabled, so their requests are disregarded and not serviced. enabling and disabling interrupt requests may be done via three mechanisms: control bits allow to switch each individual source ? on ? or ? off ? , so it may generate a request or not. the control bits (xxie) are located in the respective interrupt control registers. all interrupt requests may be enabled or disabled generally via bit ien in register psw. this control bit is the ? main switch ? that selects, if requests from any source are accepted or not. for a specific request to be arbitrated the respective source ? s enable bit and the global enable bit must both be set. the priority level automatically selects a certain group of interrupt requests that will be acknowledged, disclosing all other requests. the priority level of the source that won the arbitration is compared against the cpu ? s current level and the source is only serviced, if its level is higher than the current cpu level. changing the cpu level to a specific value via software blocks all requests on the same or a lower level. an interrupt source that is assigned to level 0 will be disabled and never be serviced. the atomic and extend instructions automatically disable all interrupt requests for the duration of the following 1...4 instructions. this is useful e.g. for semaphore handling and does not require to re-enable the interrupt system after the unseparable instruction sequence (see chapter ? system programming ? ). interrupt class management an interrupt class covers a set of interrupt sources with the same importance, i.e. the same priority from the system ? s viewpoint. interrupts of the same class must not interrupt each other. the c161pi supports this function with two features: classes with up to 4 members can be established by using the same interrupt priority (ilvl) and assigning a dedicated group level (glvl) to each member. this functionality is built-in and handled automatically by the interrupt controller. classes with more than 4 members can be established by using a number of adjacent interrupt priorities (ilvl) and the respective group levels (4 per ilvl). each interrupt service routine within this class sets the cpu level to the highest interrupt priority within the class. all requests from the same or any lower level are blocked now, i.e. no request of this class will be accepted.
  !
!"    user ? s manual 5-16 1999-08  the example below establishes 3 interrupt classes which cover 2 or 3 interrupt priorities, depending on the number of members in a class. a level 6 interrupt disables all other sources in class 2 by changing the current cpu level to 8, which is the highest priority (ilvl) in class 2. class 1 requests or pec requests are still serviced in this case. the 24 interrupt sources (excluding pec requests) are so assigned to 3 classes of priority rather than to 7 different levels, as the hardware support would do. table 5-6 software controlled interrupt classes (example) ilvl (priority) glvl interpretation 3210 15 pec service on up to 8 channels 14 13 12 xxxxinterrupt class 1 5 sources on 2 levels 11 x 10 9 8 x x x x interrupt class 2 9 sources on 3 levels 7xxxx 6x 5 x x x x interrupt class 3 5 sources on 2 levels 4x 3 2 1 0 no service!
  !
!"    user ? s manual 5-17 1999-08  5.4 saving the status during interrupt service before an interrupt request that has been arbitrated is actually serviced, the status of the current task is automatically saved on the system stack. the cpu status (psw) is saved along with the location, where the execution of the interrupted task is to be resumed after returning from the service routine. this return location is specified through the instruction pointer (ip) and, in case of a segmented memory model, the code segment pointer (csp). bit sgtdis in register syscon controls, how the return location is stored. the system stack receives the psw first, followed by the ip (unsegmented) or followed by csp and then ip (segmented mode). this optimizes the usage of the system stack, if segmentation is disabled. the cpu priority field (ilvl in psw) is updated with the priority of the interrupt request that is to be serviced, so the cpu now executes on the new level. if a multiplication or division was in progress at the time the interrupt request was acknowledged, bit mulip in register psw is set to ? 1 ? . in this case the return location that is saved on the stack is not the next instruction in the instruction flow, but rather the multiply or divide instruction itself, as this instruction has been interrupted and will be completed after returning from the service routine. figure 5-3 task status saved on the system stack the interrupt request flag of the source that is being serviced is cleared. the ip is loaded with the vector associated with the requesting source (the csp is cleared in case of segmentation) and the first instruction of the service routine is fetched from the respective vector location, which is expected to branch to the service routine itself. the data page pointers and the context pointer are not affected. when the interrupt service routine is left (reti is executed), the status information is popped from the system stack in the reverse order, taking into account the value of bit sgtdis.
  !
!"    user ? s manual 5-18 1999-08  context switching an interrupt service routine usually saves all the registers it uses on the stack, and restores them before returning. the more registers a routine uses, the more time is wasted with saving and restoring. the c161pi allows to switch the complete bank of cpu registers (gprs) with a single instruction, so the service routine executes within its own, separate context. the instruction ? scxt cp, #new_bank ? pushes the content of the context pointer (cp) on the system stack and loads cp with the immediate value ? new_bank ? , which selects a new register bank. the service routine may now use its ? own registers ? . this register bank is preserved, when the service routine terminates, i.e. its contents are available on the next call. before returning (reti) the previous cp is simply popped from the system stack, which returns the registers to the original bank. note: the first instruction following the scxt instruction must not use a gpr. resources that are used by the interrupting program must eventually be saved and restored, e.g. the dpps and the registers of the mul/div unit. 5.5 interrupt response times the interrupt response time defines the time from an interrupt request flag of an enabled interrupt source being set until the first instruction (i1) being fetched from the interrupt vector location. the basic interrupt response time for the c161pi is 3 instruction cycles. figure 5-4 pipeline diagram for interrupt response time pipeline stage cycle 1 cycle 2 cycle 3 cycle 4 fetch n n + 1 n + 2 i1 decode n - 1 n trap (1) trap (2) execute n - 2 n - 1 n trap writeback n - 3 n - 2 n - 1 n interrupt response time 1 0 ir-flag
  !
!"    user ? s manual 5-19 1999-08  all instructions in the pipeline including instruction n (during which the interrupt request flag is set) are completed before entering the service routine. the actual execution time for these instructions (e.g. waitstates) therefore influences the interrupt response time. in the figure above the respective interrupt request flag is set in cycle 1 (fetching of instruction n). the indicated source wins the prioritization round (during cycle 2). in cycle 3 a trap instruction is injected into the decode stage of the pipeline, replacing instruction n+1 and clearing the source ? s interrupt request flag to ? 0 ? . cycle 4 completes the injected trap instruction (save psw, ip and csp, if segmented mode) and fetches the first instruction (i1) from the respective vector location. all instructions that entered the pipeline after setting of the interrupt request flag (n+1, n+2) will be executed after returning from the interrupt service routine. the minimum interrupt response time is 5 states (10 tcl). this requires program execution from the internal code memory, no external operand read requests and setting the interrupt request flag during the last state of an instruction cycle. when the interrupt request flag is set during the first state of an instruction cycle, the minimum interrupt response time under these conditions is 6 state times (12 tcl). the interrupt response time is increased by all delays of the instructions in the pipeline that are executed before entering the service routine (including n).  when internal hold conditions between instruction pairs n-2/n-1 or n-1/n occur, or instruction n explicitly writes to the psw or the sp, the minimum interrupt response time may be extended by 1 state time for each of these conditions.  when instruction n reads an operand from the internal code memory, or when n is a call, return, trap, or mov rn, [rm+ #data16] instruction, the minimum interrupt response time may additionally be extended by 2 state times during internal code memory program execution.  in case instruction n reads the psw and instruction n-1 has an effect on the condition flags, the interrupt response time may additionally be extended by 2 state times. the worst case interrupt response time during internal code memory program execution adds to 12 state times (24 tcl). any reference to external locations increases the interrupt response time due to pipeline related access priorities. the following conditions have to be considered:  instruction fetch from an external location  operand read from an external location  result write-back to an external location depending on where the instructions, source and destination operands are located, there are a number of combinations. note, however, that only access conflicts contribute to the delay.
  !
!"    user ? s manual 5-20 1999-08  a few examples illustrate these delays:  the worst case interrupt response time including external accesses will occur, when instructions n, n+1 and n+2 are executed out of external memory, instructions n-1 and n require external operand read accesses, instructions n-3 through n write back external operands, and the interrupt vector also points to an external location. in this case the interrupt response time is the time to perform 9 word bus accesses, because instruction i1 cannot be fetched via the external bus until all write, fetch and read requests of preceding instructions in the pipeline are terminated.  when the above example has the interrupt vector pointing into the internal code memory, the interrupt response time is 7 word bus accesses plus 2 states, because fetching of instruction i1 from internal code memory can start earlier.  when instructions n, n+1 and n+2 are executed out of external memory and the interrupt vector also points to an external location, but all operands for instructions n- 3 through n are in internal memory, then the interrupt response time is the time to perform 3 word bus accesses.  when the above example has the interrupt vector pointing into the internal code memory, the interrupt response time is 1 word bus access plus 4 states. after an interrupt service routine has been terminated by executing the reti instruction, and if further interrupts are pending, the next interrupt service routine will not be entered until at least two instruction cycles have been executed of the program that was interrupted. in most cases two instructions will be executed during this time. only one instruction will typically be executed, if the first instruction following the reti instruction is a branch instruction (without cache hit), or if it reads an operand from internal code memory, or if it is executed out of the internal ram. note: a bus access in this context includes all delays which can occur during an external bus cycle.
  !
!"    user ? s manual 5-21 1999-08  5.6 pec response times the pec response time defines the time from an interrupt request flag of an enabled interrupt source being set until the pec data transfer being started. the basic pec response time for the c161pi is 2 instruction cycles. figure 5-5 pipeline diagram for pec response time in the figure above the respective interrupt request flag is set in cycle 1 (fetching of instruction n). the indicated source wins the prioritization round (during cycle 2). in cycle 3 a pec transfer ? instruction ? is injected into the decode stage of the pipeline, suspending instruction n+1 and clearing the source's interrupt request flag to '0'. cycle 4 completes the injected pec transfer and resumes the execution of instruction n+1. all instructions that entered the pipeline after setting of the interrupt request flag (n+1, n+2) will be executed after the pec data transfer. note: when instruction n reads any of the pec control registers pecc7...pecc0, while a pec request wins the current round of prioritization, this round is repeated and the pec data transfer is started one cycle later. the minimum pec response time is 3 states (6 tcl). this requires program execution from the internal code memory, no external operand read requests and setting the interrupt request flag during the last state of an instruction cycle. when the interrupt request flag is set during the first state of an instruction cycle, the minimum pec response time under these conditions is 4 state times (8 tcl). pipeline stage cycle 1 cycle 2 cycle 3 cycle 4 fetch n n + 1 n + 2 n + 2 decode n - 1 n pec n + 1 execute n - 2 n - 1 n pec writeback n - 3 n - 2 n - 1 n pec response time 1 0 ir-flag
  !
!"    user ? s manual 5-22 1999-08  the pec response time is increased by all delays of the instructions in the pipeline that are executed before starting the data transfer (including n).  when internal hold conditions between instruction pairs n-2/n-1 or n-1/n occur, the minimum pec response time may be extended by 1 state time for each of these conditions.  when instruction n reads an operand from the internal code memory, or when n is a call, return, trap, or mov rn, [rm+ #data16] instruction, the minimum pec response time may additionally be extended by 2 state times during internal code memory program execution.  in case instruction n reads the psw and instruction n-1 has an effect on the condition flags, the pec response time may additionally be extended by 2 state times. the worst case pec response time during internal code memory program execution adds to 9 state times (18 tcl). any reference to external locations increases the pec response time due to pipeline related access priorities. the following conditions have to be considered:  instruction fetch from an external location  operand read from an external location  result write-back to an external location depending on where the instructions, source and destination operands are located, there are a number of combinations. note, however, that only access conflicts contribute to the delay. a few examples illustrate these delays:  the worst case interrupt response time including external accesses will occur, when instructions n and n+1 are executed out of external memory, instructions n-1 and n require external operand read accesses and instructions n-3, n-2 and n-1 write back external operands. in this case the pec response time is the time to perform 7 word bus accesses.  when instructions n and n+1 are executed out of external memory, but all operands for instructions n-3 through n-1 are in internal memory, then the pec response time is the time to perform 1 word bus access plus 2 state times. once a request for pec service has been acknowledged by the cpu, the execution of the next instruction is delayed by 2 state times plus the additional time it might take to fetch the source operand from internal code memory or external memory and to write the destination operand over the external bus in an external program environment. note: a bus access in this context includes all delays which can occur during an external bus cycle.
  !
!"    user ? s manual 5-23 1999-08  5.7 interrupt node sharing interrupt nodes may be shared between several module requests either if the requests are generated mutually exclusive or if the requests are generated at a low rate. if more than one source is enabled in this case the interrupt handler will first have to determine the requesting source. however, this overhead is not critical for low rate requests. this node sharing is controlled via the sub-node interrupt control register isnc which provides a separate request flag and enable bit for each supported request source. the interrupt level used for arbitration is determined by the node control register (...ic). note: in order to ensure compatibility with other derivatives application software should never set reserved bits within register isnc. isnc intr. subnode ctrl. reg. esfr (f1de h /ef h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------------ pll ie pll ir rtc ie rtc ir - - - - - - - - - - - - rw rw rw rw bit function xxir interrupt request flag for source xx 0: no request from source xx pending. 1: source xx has raised an interrupt request. xxie interrupt enable control bit for source xx 0: source xx interrupt request is disabled. 1: source xx interrupt request is enabled. table 5-7 sub-node control bit allocation bit pos. interrupt source associated node 15...4 reserved. reserved. 3|2 pll / owd xp3ic 1|0 rtc xp3ic
  !
!"    user ? s manual 5-24 1999-08  5.8 external interrupts although the c161pi has no dedicated intr input pins, it provides many possibilities to react on external asynchronous events by using a number of io lines for interrupt input. the interrupt function may either be combined with the pin ? s main function or may be used instead of it, i.e. if the main pin function is not required. interrupt signals may be connected to:  ex7in...ex0in, the fast external interrupt input pins,  t4in, t2in, the timer input pins  capin, the capture input of gpt2 for each of these pins either a positive, a negative, or both a positive and a negative external transition can be selected to cause an interrupt or pec service request. the edge selection is performed in the control register of the peripheral device associated with the respective port pin. the peripheral must be programmed to a specific operating mode to allow generation of an interrupt by the external signal. the priority of the interrupt request is determined by the interrupt control register of the respective peripheral interrupt source, and the interrupt vector of this source will be used to service the external interrupt request. note: in order to use any of the listed pins as external interrupt input, it must be switched to input mode via its direction control bit dpx.y in the respective port direction control register dpx. table 5-8 pins to be used as external interrupt inputs port pin original function control register p2.15-8/ex7-0in fast external interrupt input pin exicon p3.7/t2in auxiliary timer t2 input pin t2con p3.5/t4in auxiliary timer t4 input pin t4con p3.2/capin gpt2 capture input pin t5con
  !
!"    user ? s manual 5-25 1999-08  pins t2in or t4in can be used as external interrupt input pins when the associated auxiliary timer t2 or t4 in block gpt1 is configured for capture mode. this mode is selected by programming the mode control fields t2m or t4m in control registers t2con or t4con to 101 b . the active edge of the external input signal is determined by bit fields t2i or t4i. when these fields are programmed to x01 b , interrupt request flags t2ir or t4ir in registers t2ic or t4ic will be set on a positive external transition at pins t2in or t4in, respectively. when t2i or t4i are programmed to x10 b , then a negative external transition will set the corresponding request flag. when t2i or t4i are programmed to x11 b , both a positive and a negative transition will set the request flag. in all three cases, the contents of the core timer t3 will be captured into the auxiliary timer registers t2 or t4 based on the transition at pins t2in or t4in. when the interrupt enable bits t2ie or t4ie are set, a pec request or an interrupt request for vector t2int or t4int will be generated. pin capin differs slightly from the timer input pins as it can be used as external interrupt input pin without affecting peripheral functions. when the capture mode enable bit t5sc in register t5con is cleared to ? 0 ? , signal transitions on pin capin will only set the interrupt request flag crir in register cric, and the capture function of register caprel is not activated. so register caprel can still be used as reload register for gpt2 timer t5, while pin capin serves as external interrupt input. bit field ci in register t5con selects the effective transition of the external interrupt input signal. when ci is programmed to 01 b , a positive external transition will set the interrupt request flag. ci=10 b selects a negative transition to set the interrupt request flag, and with ci=11 b , both a positive and a negative transition will set the request flag. when the interrupt enable bit crie is set, an interrupt request for vector crint or a pec request will be generated. note: the non-maskable interrupt input pin nmi and the reset input rstin provide another possibility for the cpu to react on an external input signal. nmi and rstin are dedicated input pins, which cause hardware traps.
  !
!"    user ? s manual 5-26 1999-08  fast external interrupts the input pins that may be used for external interrupts are sampled every 16 tcl, i.e. external events are scanned and detected in timeframes of 16 tcl. the c161pi provides 8 interrupt inputs that are sampled every 2 tcl, so external events are captured faster than with standard interrupt inputs. the 8 pins of port 2 (p2.15-p2.8) can individually be programmed to this fast interrupt mode, where also the trigger transition (rising, falling or both) can be selected. the external interrupt control register exicon controls this feature for all 8 pins. note: the fast external interrupt inputs are sampled every 2 tcl. the interrupt request arbitration and processing, however, is executed every 8 tcl. the interrupt control registers listed below (cc15ic...cc8ic) control the fast external interrupts of the c161pi . these fast external interrupt nodes and vectors are named according to the c167 ? s capcom channels cc15...cc8, so interrupt nodes receive equal names throughout the architecture. see register description below. exicon external intr. ctrl. reg. esfr (f1c0 h /e0 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 exi7es exi6es exi5es exi4es exi3es exi2es exi1es exi0es rw rw rw rw rw rw rw rw bit function exixes external interrupt x edge selection field (x=7...0) 0 0: fast external interrupts disabled: standard mode 0 1: interrupt on positive edge (rising) 1 0: interrupt on negative edge (falling) 1 1: interrupt on any edge (rising or falling)
  !
!"    user ? s manual 5-27 1999-08  note: please refer to the general interrupt control register description for an explanation of the control fields. ccxic capcom x intr. ctrl. reg. sfr(see table) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ccx ir ccx ie ilvl glvl - - - - - - - - rwh rw rw rw table 5-9 fast external interrupt control register addresses register address external interrupt cc8ic ff88 h / c4 h ex0in cc9ic ff8a h / c5 h ex1in cc10ic ff8c h / c6 h ex2in cc11ic ff8e h / c7 h ex3in cc12ic ff90 h / c8 h ex4in cc13ic ff92 h / c9 h ex5in cc14ic ff94 h / ca h ex6in cc15ic ff96 h / cb h ex7in
  !
!"    user ? s manual 5-28 1999-08  external interrupts during sleep mode during sleep mode all peripheral clock signals are deactivated which also disables the standard edge detection logic for the fast external interrupts. however, transitions on these interrupt inputs must be recognized in order to initiate the wakeup. therefore during sleep mode a special edge detection logic for the fast external interrupts (exzin) is activated, which requires no clock signal (therefore also works in sleep mode) and is equipped with an analog noise filter. this filter suppresses spikes (generated by noise) up to 10 ns. input pulses with a duration of 100 ns minimum are recognized and generate an interrupt request. this filter delays the recognition of an external wakeup signal by approx. 100 ns, but the spike suppression ensures safe and robust operation of the sleep/wakeup mechanism in an active environment. figure 5-6 input noise filter operation input signal interrupt request rejected recognized 10ns 100ns
  !
!"    user ? s manual 5-29 1999-08  5.9 trap functions traps interrupt the current execution similar to standard interrupts. however, trap functions offer the possibility to bypass the interrupt system ? s prioritization process in cases where immediate system reaction is required. trap functions are not maskable and always have priority over interrupt requests on any priority level. the c161pi provides two different kinds of trapping mechanisms. hardware traps are triggered by events that occur during program execution (e.g. illegal access or undefined opcode), software traps are initiated via an instruction within the current execution flow. software traps the trap instruction is used to cause a software call to an interrupt service routine. the trap number that is specified in the operand field of the trap instruction determines which vector location in the address range from 00 ? 0000 h through 00 ? 01fc h will be branched to. executing a trap instruction causes a similar effect as if an interrupt at the same vector had occurred. psw, csp (in segmentation mode), and ip are pushed on the internal system stack and a jump is taken to the specified vector location. when segmentation is enabled and a trap is executed, the csp for the trap service routine is set to code segment 0. no interrupt request flags are affected by the trap instruction. the interrupt service routine called by a trap instruction must be terminated with a reti (return from interrupt) instruction to ensure correct operation. note: the cpu level in register psw is not modified by the trap instruction, so the service routine is executed on the same priority level from which it was invoked. therefore, the service routine entered by the trap instruction can be interrupted by other traps or higher priority interrupts, other than when triggered by a hardware trap. hardware traps hardware traps are issued by faults or specific system states that occur during runtime of a program (not identified at assembly time). a hardware trap may also be triggered intentionally, e.g. to emulate additional instructions by generating an illegal opcode trap. the c161pi distinguishes eight different hardware trap functions. when a hardware trap condition has been detected, the cpu branches to the trap vector location for the respective trap condition. depending on the trap condition, the instruction which caused the trap is either completed or cancelled (i.e. it has no effect on the system state) before the trap handling routine is entered. hardware traps are non-maskable and always have priority over every other cpu activity. if several hardware trap conditions are detected within the same instruction cycle, the highest priority trap is serviced (see table in section ? interrupt system structure ? ).
  !
!"    user ? s manual 5-30 1999-08  psw, csp (in segmentation mode), and ip are pushed on the internal system stack and the cpu level in register psw is set to the highest possible priority level (i.e. level 15), disabling all interrupts. the csp is set to code segment zero, if segmentation is enabled. a trap service routine must be terminated with the reti instruction. the eight hardware trap functions of the c161pi are divided into two classes: class a traps are  external non-maskable interrupt (nmi )  stack overflow  stack underflow trap these traps share the same trap priority, but have an individual vector address. class b traps are  undefined opcode  protection fault  illegal word operand access  illegal instruction access  illegal external bus access trap these traps share the same trap priority, and the same vector address. the bit-addressable trap flag register (tfr) allows a trap service routine to identify the kind of trap which caused the exception. each trap function is indicated by a separate request flag. when a hardware trap occurs, the corresponding request flag in register tfr is set to '1'. the reset functions (hardware, software, watchdog) may be regarded as a type of trap. reset functions have the highest system priority (trap priority iii). class a traps have the second highest priority (trap priority ii), on the 3rd rank are class b traps, so a class a trap can interrupt a class b trap. if more than one class a trap occur at a time, they are prioritized internally, with the nmi trap on the highest and the stack underflow trap on the lowest priority. all class b traps have the same trap priority (trap priority i). when several class b traps get active at a time, the corresponding flags in the tfr register are set and the trap service routine is entered. since all class b traps have the same vector, the priority of service of simultaneously occurring class b traps is determined by software in the trap service routine. a class a trap occurring during the execution of a class b trap service routine will be serviced immediately. during the execution of a class a trap service routine, however, any class b trap occurring will not be serviced until the class a trap service routine is exited with a reti instruction. in this case, the occurrence of the class b trap condition is stored in the tfr register, but the ip value of the instruction which caused this trap is lost.
  !
!"    user ? s manual 5-31 1999-08  note: the trap service routine must clear the respective trap flag, otherwise a new trap will be requested after exiting the service routine. setting a trap request flag by software causes the same effects as if it had been set by hardware. in the case where e.g. an undefined opcode trap (class b) occurs simultaneously with an nmi trap (class a), both the nmi and the undopc flag is set, the ip of the instruction with the undefined opcode is pushed onto the system stack, but the nmi trap is executed. after return from the nmi service routine, the ip is popped from the stack and immediately pushed again because of the pending undopc trap. tfr trap flag register sfr (ffac h /d6 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 nmi stk of stk uf ----- und opc --- prt flt ill opa ill ina ill bus rwh rwh rwh - - - - rwh - - - rwh rwh rwh rwh bit function illbus illegal external bus access flag an external access has been attempted with no external bus defined. illina illegal instruction access flag a branch to an odd address has been attempted. illopa illegal word operand access flag a word operand access (read or write) to an odd address has been attempted. prtflt protection fault flag a protected instruction with an illegal format has been detected. undopc undefined opcode flag the currently decoded instruction has no valid c161pi opcode. stkuf stack underflow flag the current stack pointer value exceeds the content of register stkun. stkof stack overflow flag the current stack pointer value falls below the content of reg. stkov. nmi non maskable interrupt flag a negative transition (falling edge) has been detected on pin nmi .
  !
!"    user ? s manual 5-32 1999-08  external nmi trap whenever a high to low transition on the dedicated external nmi pin (non-maskable interrupt) is detected, the nmi flag in register tfr is set and the cpu will enter the nmi trap routine. the ip value pushed on the system stack is the address of the instruction following the one after which normal processing was interrupted by the nmi trap. note: the nmi pin is sampled with every cpu clock cycle to detect transitions. stack overflow trap whenever the stack pointer is decremented to a value which is less than the value in the stack overflow register stkov, the stkof flag in register tfr is set and the cpu will enter the stack overflow trap routine. which ip value will be pushed onto the system stack depends on which operation caused the decrement of the sp. when an implicit decrement of the sp is made through a push or call instruction, or upon interrupt or trap entry, the ip value pushed is the address of the following instruction. when the sp is decremented by a subtract instruction, the ip value pushed represents the address of the instruction after the instruction following the subtract instruction. for recovery from stack overflow it must be ensured that there is enough excess space on the stack for saving the current system state (psw, ip, in segmented mode also csp) twice. otherwise, a system reset should be generated. stack underflow trap whenever the stack pointer is incremented to a value which is greater than the value in the stack underflow register stkun, the stkuf flag is set in register tfr and the cpu will enter the stack underflow trap routine. again, which ip value will be pushed onto the system stack depends on which operation caused the increment of the sp. when an implicit increment of the sp is made through a pop or return instruction, the ip value pushed is the address of the following instruction. when the sp is incremented by an add instruction, the pushed ip value represents the address of the instruction after the instruction following the add instruction. undefined opcode trap when the instruction currently decoded by the cpu does not contain a valid c161pi opcode, the undopc flag is set in register tfr and the cpu enters the undefined opcode trap routine. the ip value pushed onto the system stack is the address of the instruction that caused the trap. this can be used to emulate unimplemented instructions. the trap service routine can examine the faulting instruction to decode operands for unimplemented opcodes based on the stacked ip. in order to resume processing, the stacked ip value must be incremented by the size of the undefined instruction, which is determined by the user, before a reti instruction is executed.
  !
!"    user ? s manual 5-33 1999-08  protection fault trap whenever one of the special protected instructions is executed where the opcode of that instruction is not repeated twice in the second word of the instruction and the byte following the opcode is not the complement of the opcode, the prtflt flag in register tfr is set and the cpu enters the protection fault trap routine. the protected instructions include diswdt, einit, idle, pwrdn, srst, and srvwdt. the ip value pushed onto the system stack for the protection fault trap is the address of the instruction that caused the trap. illegal word operand access trap whenever a word operand read or write access is attempted to an odd byte address, the illopa flag in register tfr is set and the cpu enters the illegal word operand access trap routine. the ip value pushed onto the system stack is the address of the instruction following the one which caused the trap. illegal instruction access trap whenever a branch is made to an odd byte address, the illina flag in register tfr is set and the cpu enters the illegal instruction access trap routine. the ip value pushed onto the system stack is the illegal odd target address of the branch instruction. illegal external bus access trap whenever the cpu requests an external instruction fetch, data read or data write, and no external bus configuration has been specified, the illbus flag in register tfr is set and the cpu enters the illegal bus access trap routine. the ip value pushed onto the system stack is the address of the instruction following the one which caused the trap.
  !
!"    user ? s manual 5-34 1999-08 
  %&  user ? s manual 6-1 1999-08  6 clock generation all activities of the c161pi ? s controller hardware and its on-chip peripherals are controlled via the system clock signal  cpu . this reference clock is generated in three stages (see also figure below):  oscillator the on-chip pierce oscillator can either run with an external crystal and appropriate oscillator circuitry or it can be driven by an external oscillator.  frequency control the input clock signal feeds the controller hardware... ...directly, providing phase coupled operation on not too high input frequency ...divided by 2 in order to get 50% duty cycle clock signal ...via an on-chip phase locked loop (pll) providing maximum performance on low input frequency ...via the slow down divider (sdd) in order to reduce the power consumption. the resulting internal clock signal is referred to as ? cpu clock ?  cpu .  clock drivers the cpu clock is distributed via separate clock drivers which feed the cpu itself and two groups of peripheral modules. the rtc is fed with the prescaled oscillator clock (  rtc ) via a separate clock driver, so it is not affected by the clock control functions. figure 6-1 cpu clock generation stages prescaler pll sdd cpu peripherals, interfaces ports, intr.ctrl. ccd pcd icd idle mode pcddis p.d.mode rtc osc oscillator clock drivers frequency control 32:1  rtc
  %&  user ? s manual 6-2 1999-08  6.1 oscillator the main oscillator of the c161pi is a power optimized pierce oscillator providing an inverter and a feedback element. pins xtal1 and xtal2 connect the inverter to the external crystal. the standard external oscillator circuitry (see figure below) comprises the crystal, two low end capacitors and series resistor (rx2) to limit the current through the crystal. the additional lc combination is only required for 3rd overtone crystals to suppress oscillation in the fundamental mode. a test resistor (r q ) may be temporarily inserted to measure the oscillation allowance of the oscillator circuitry. figure 6-2 external oscillator circuitry the on-chip oscillator is optimized for an input frequency range of 1 to 16 mhz. an external clock signal (e.g. from an external oscillator or from a master device) may be fed to the input xtal1. the pierce oscillator then is not required to support the oscillation itself but is rather driven by the input signal. in this case the input frequency range may be 0 to 50 mhz (please note that the maximum applicable input frequency is limited by the device ? s maximum cpu frequency). for input frequencies above 25...30 mhz the oscillator ? s output should be terminated as shown in the figure below, at lower frequencies it may be left open. this termination improves the operation of the oscillator by filtering out frequencies above the intended oscillator frequency. xtal1 xtal2 rx2 r q
  %&  user ? s manual 6-3 1999-08  figure 6-3 oscillator output termination note: it is strongly recommended to measure the oscillation allowance (or margin) in the final target system (layout) to determine the optimum parameters for the oscillator operation. 3k ? 15pf xtal1 xtal2 input clock
  %&  user ? s manual 6-4 1999-08  6.2 frequency control the cpu clock is generated from the oscillator clock in either of two software selectable ways: the basic clock is the standard operating clock for the c161pi and is required to deliver the intended maximum performance. the configuration via port0 (clkcfg) after a long hardware reset determines one of three possible basic clock generation modes:  direct drive: the oscillator clock is directly fed to the controller hardware.  prescaler: the oscillator clock is divided by 2 to achieve a 50% duty cycle.  pll: the oscillator clock is multiplied by a configurable factor of f = 1.5...5. the slow down clock is the oscillator clock divided by a programmable factor of 1...32 (additional 2:1 divider in prescaler mode). this alternate possibility runs the c161pi at a lower frequency (depending on the programmed slow down factor) and thus greatly reduces its power consumption. figure 6-4 frequency control paths the internal operation of the c161pi is controlled by the internal cpu clock f cpu . both edges of the cpu clock can trigger internal (e.g. pipeline) or external (e.g. bus cycles) operations (see figure below). configuration software pll sdd 2:1 oscillator clock cpu clock f cpu f osc owd
  %&  user ? s manual 6-5 1999-08  figure 6-5 generation mechanisms for the cpu clock tcl tcl tcl tcl  cpu  osc  cpu  osc phase locked loop operation direct clock drive tcl tcl  cpu  osc prescaler operation tcl tcl  cpu  osc sdd operation tcl tcl  cpu (clkrel=2, direct drive) (clkrel=2, prescaler)
  %&  user ? s manual 6-6 1999-08  direct drive when direct drive is configured (clkcfg= ? 011 ? ) the c161pi ? s clock system is directly fed from the external clock input, i.e.  cpu =  osc . this allows operation of the c161pi with a reasonably small fundamental mode crystal. the specified minimum values for the cpu clock phases (tcls) must be respected. therefore the maximum input clock frequency depends on the clock signal ? s duty cycle. prescaler operation when prescaler operation is configured (clkcfg= ? 001 ? ) the c161pi ? s input clock is divided by 2 to generate then cpu clock signal, i.e.  cpu =  osc /2. this requires the oscillator (or input clock) to run on 2 times the intended operating frequency but guarantees a 50% duty cycle for the internal clock system independent of the input clock signal ? s waveform. pll operation when pll operation is configured (via clkcfg) the c161pi ? s input clock is fed to the on-chip phase locked loop circuit which multiplies its frequency by a factor of f = 1.5...5 (selectable via clkcfg, see table below) and generates a cpu clock signal with 50% duty cycle, i.e.  cpu =  osc *f. the on-chip pll circuit allows operation of the c161pi on a low frequency external clock while still providing maximum performance. the pll also provides fail safe mechanisms which allow the detection of frequency deviations and the execution of emergency actions in case of an external clock failure. when the pll detects a missing input clock signal it generates an interrupt request. this warning interrupt indicates that the pll frequency is no more locked, i.e. no more stable. this occurs when the input clock is unstable and especially when the input clock fails completely, e.g. due to a broken crystal. in this case the synchronization mechanism will reduce the pll output frequency down to the pll ? s base frequency (2...5 mhz). the base frequency is still generated and allows the cpu to execute emergency actions in case of a loss of the external clock. on power-up the pll provides a stable clock signal within ca. 1 ms after  dd has reached the specified valid range, even if there is no external clock signal (in this case the pll will run on its base frequency of 2...5 mhz). the pll starts synchronizing with the external clock signal as soon as it is available. within ca. 1 ms after stable oscillations of the external clock within the specified frequency range the pll will be synchronous with this clock at a frequency of f *  osc , i.e. the pll locks to the external clock. when pll operation is selected the cpu clock is a selectable multiple of the oscillator frequency, i.e. the input frequency.
  %&  user ? s manual 6-7 1999-08  the table below lists the possible selections. the pll constantly synchronizes to the external clock signal. due to the fact that the external frequency is 1/ f ? th of the pll output frequency the output frequency may be slightly higher or lower than the desired frequency. this jitter is irrelevant for longer time periods. for short periods (1...4 cpu clock cycles) it remains below 4%. figure 6-6 pll block diagram table 6-1 c161pi clock generation modes p0.15-13 (p0h.7-5) cpu frequency  cpu =  osc * f external clock input range 1) 1) the external clock input range refers to a cpu clock range of 10...25 mhz. notes 1 1 1  osc * 4 2.5 to 6.25 mhz default configuration 1 1 0  osc * 3 3.33 to 8.33 mhz 10 1  osc * 2 5 to 12.5 mhz 1 0 0  osc * 5 2 to 5 mhz 0 1 1  osc * 1 1 to 25 mhz direct drive 2) 2) the maximum frequency depends on the duty cycle of the external clock signal. in emulation mode pin p0.15 (p0h.7) is inverted, i.e. the configuration ? 111 ? would select direct drive in emulation mode. 0 1 0  osc * 1.5 6.66 to 16.6 mhz 0 0 1  osc / 2 2 to 50 mhz cpu clock via prescaler 0 0 0  osc * 2.5 4 to 10 mhz pll circuit f pll = f * f in reset sleep f reset pwrdn isnc / f pll f in f cpu lock clkcfg (rp0h.7-5) owd clkcon xp3int
  %&  user ? s manual 6-8 1999-08  6.3 oscillator watchdog the c161pi provides an oscillator watchdog (owd) which monitors the clock signal fed to input xtal1 of the on-chip oscillator (either with a crystal or via external clock drive) in prescaler or direct drive mode (not if the pll provides the basic clock). for this operation the pll provides a clock signal (base frequency) which is used to supervise transitions on the oscillator clock. this pll clock is independent from the xtal1 clock. when the expected oscillator clock transitions are missing the owd activates the pll unlock / owd interrupt node and supplies the cpu with the pll clock signal instead of the selected oscillator clock. under these circumstances the pll will oscillate with its base frequency. if the oscillator clock fails while the pll provides the basic clock the system will be supplied with the pll base frequency anyway. with this pll clock signal the cpu can either execute a controlled shutdown sequence bringing the system into a defined and safe idle state, or it can provide an emergency operation of the system with reduced performance based on this (normally slower) emergency clock. note: the cpu clock source is only switched back to the oscillator clock after a hardware reset. the oscillator watchdog can be disabled by setting bit owddis in register syscon. in this case the pll remains idle and provides no clock signal, while the cpu clock signal is derived directly from the oscillator clock or via prescaler or sdd. also no interrupt request will be generated in case of a missing oscillator clock. note: at the end of an external reset bit owddis reflects the inverted level of pin rd at that time. thus the oscillator watchdog may also be disabled via hardware by (externally) pulling the rd line low upon a reset, similar to the standard reset configuration via port0. the oscillator watchdog cannot provide full security while the cpu clock signal is generated by the slowdown divider, because the owd cannot switch to the pll clock in this case (see figure 6-4 on page 4). owd interrupts are only recognizable if  osc is still available (e.g. input frequency too low or intermittent failure only). a broken crystal cannot be detected by software (owd interrupt server) as no sdd clock is available in such a case.
  %&  user ? s manual 6-9 1999-08  6.4 clock drivers the operating clock signal  cpu is distributed to the controller hardware via several clock drivers which are disabled under certain circumstances. the real time clock rtc is clocked via a separate clock driver which delivers the prescaled oscillator clock (contrary to the other clock drivers). the table below summarizes the different clock drivers and their function, especially in power reduction modes: note: disabling pcd by setting bit pcddis stops the clock signal for all connected modules. make sure that all these modules are in a safe state before stopping their clock signal. the port input and output values will not change while pcd is disabled (asc0 and ssc will still operate, if active), clkout will be high if enabled. please also respect the hints given in section ? flexible peripheral management ? of chapter ? power management ? . table 6-2 clock drivers description clock driver clock signal active mode idle mode power down and sleep mode connected circuitry ccd cpu clock driver  cpu on off off cpu, internal memory modules (iram, rom/otp/flash) icd interface clock driver  cpu on on off asc0, wdt, ssc, interrupt detection circuitry pcd peripheral clock driver  cpu control via pcddis control via pcddis off (x)peripherals (timers, etc.) except those driven by icd, interrupt controller, ports rcd rtc clock driver  rtc on on control via pdcon / sleep- con realtime clock
  %&  user ? s manual 6-10 1999-08 
   user ? s manual 7-1 1999-08  7 parallel ports in order to accept or generate single external control signals or parallel data, the c161pi provides up to 76 parallel io lines organized into six 8-bit io ports (port0 made of p0h and p0l, port1 made of p1h and p1l, port 2, port 6), one 15-bit io port (port 3), one 7-bit io port (port 4) and one 6-bit input port (port 5). these port lines may be used for general purpose input/output controlled via software or may be used implicitly by the c161pi ? s integrated peripherals or the external bus controller. all port lines are bit addressable, and all input/output lines are individually (bit-wise) programmable as inputs or outputs via direction registers (except port 5, of course). the io ports are true bidirectional ports which are switched to high impedance state when configured as inputs. the output drivers of three io ports (2, 3, 6) can be configured (pin by pin) for push/pull operation or open-drain operation via control registers. the logic level of a pin is clocked into the input latch once per state time, regardless whether the port is configured for input or output. figure 7-1 sfrs and pins associated with the parallel ports data input / output registers direction control registers diverse control registers odp2 e odp6 e p1l p1h dp1l e dp1h e p0l p0h dp0l e dp0h e odp3 e p5didis p3 p4 p5 p6 p2 dp3 dp4 dp6 dp2 pdcr e picon e
   user ? s manual 7-2 1999-08  a write operation to a port pin configured as an input causes the value to be written into the port output latch, while a read operation returns the latched state of the pin itself. a read-modify-write operation reads the value of the pin, modifies it, and writes it back to the output latch. writing to a pin configured as an output (dpx.y= ? 1 ? ) causes the output latch and the pin to have the written value, since the output buffer is enabled. reading this pin returns the value of the output latch. a read-modify-write operation reads the value of the output latch, modifies it, and writes it back to the output latch, thus also modifying the level at the pin. 7.1 input threshold control the standard inputs of the c161pi determine the status of input signals according to ttl levels. in order to accept and recognize noisy signals, cmos-like input thresholds can be selected instead of the standard ttl thresholds for all pins of specific ports. these special thresholds are defined above the ttl thresholds and feature a defined hysteresis to prevent the inputs from toggling while the respective input signal level is near the thresholds. the port input control register picon allows to select these thresholds for each byte of the indicated ports, i.e. 8-bit ports are controlled by one bit each while 16-bit ports are controlled by two bits each. picon port input control register esfr (f1c4 h /e2 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 --- p4l in p3h in p3l in -- - - - - - - - - - - - rw rw rw - - bit function pxlin port x low byte input level selection 0: pins px[7-0] switch on standard ttl input levels 1: pins px[7-0] switch on special threshold input levels pxhin port x high byte input level selection 0: pins px[15-8] switch on standard ttl input levels 1: pins px[15-8] switch on special threshold input levels
   user ? s manual 7-3 1999-08  all options for individual direction and output mode control are available for each pin independent from the selected input threshold. the input hysteresis provides stable inputs from noisy or slowly changing external signals. the internal signal only changes its state when the external input signal has changed its level at least by the voltage defined by the hysteresis. figure 7-2 hysteresis for special input thresholds input level bit state hysteresis
   user ? s manual 7-4 1999-08  7.2 output driver control the output driver of a port pin is activated by switching the respective pin to output, i.e. dpx.y = ? 1 ? . the value that is driven to the pin is determined by the port output latch or by the associated alternate function (e.g. address, peripheral io, etc.). the user software can control the characteristics of the output driver via the following mechanisms:  open drain mode : the upper (push) transistor is always disabled. only ? 0 ? is driven actively, an external pullup is required.  edge characteristic : the rise/fall time of an output signal can be selected. open drain mode in the c161pi certain ports provide open drain control, which allows to switch the output driver of a port pin from a push/pull configuration to an open drain configuration. in push/ pull mode a port output driver has an upper and a lower transistor, thus it can actively drive the line either to a high or a low level. in open drain mode the upper transistor is always switched off, and the output driver can only actively drive the line to a low level. when writing a ? 1 ? to the port latch, the lower transistor is switched off and the output enters a high-impedance state. the high level must then be provided by an external pullup device. with this feature, it is possible to connect several port pins together to a wired-and configuration, saving external glue logic and/or additional software overhead for enabling/disabling output signals. this feature is controlled through the respective open drain control registers odpx which are provided for each port that has this feature implemented. these registers allow the individual bit-wise selection of the open drain mode for each port line. if the respective control bit odpx.y is ? 0 ? (default after reset), the output driver is in the push/ pull mode. if odpx.y is ? 1 ? , the open drain configuration is selected. note that all odpx registers are located in the esfr space. figure 7-3 output drivers in push/pull mode and in open drain mode
   user ? s manual 7-5 1999-08  edge characteristic this defines the rise/fall time for the respective output, i.e. the output transition time. slow edges reduce the peak currents that are drawn when changing the voltage level of an external capacitive load. for a bus interface, however, fast edges may still be required. edge characteristic effects the pre-driver which controls the final output driver stage. two driving levels (fast/reduced edge) can be selected for two groups of pins (bus interface / non-bus pins) respectively. figure 7-4 structure of output driver with edge control the figure below summarizes the effects of the driver characteristics: edge characteristic generally influences the output signal ? s shape . figure 7-5 general output signal waveforms data signal push pull driver control logic pin edge control open drain control control signals driver stage fast edge slow edge
   user ? s manual 7-6 1999-08  the port driver control register pdcr provides the corresponding control bits. a separate control bit is provided for bus pins as well as for non-bus pins. pdcr port driver control register esfr (f0aa h /55 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - - ------- nbp ec --- bip ec - - - - - - - - - - - rw - - - rw bit function bipec bus interface pins edge characteristic (defines the output rise/fall time t rf ) 0: fast edge mode, rise/fall times depend on the driver ? s dimensioning. 1: reduced edge mode. bipec controls: port0, port1, port 4, port 6.4-0, rd , wr , ale, clkout, bhe /wrh , ready (emulation mode only). nbpec non-bus pins edge characteristic (defines the output rise/fall time t rf ) 0: fast edge mode, rise/fall times depend on the driver ? s dimensioning. 1: reduced edge mode. nbpec controls: port 2, port 3, port 6.7-5, rstout
   user ? s manual 7-7 1999-08  7.3 alternate port functions in order to provide a maximum of flexibility for different applications and their specific io requirements, port lines have programmable alternate input or output functions associated with them. if an alternate output function of a pin is to be used, the direction of this pin must be programmed for output (dpx.y= ? 1 ? ), except for some signals that are used directly after reset and are configured automatically. otherwise the pin remains in the high-impedance state and is not effected by the alternate output function. the respective port latch should hold a ? 1 ? , because its output is combined with the alternate output data. x-peripherals (peripherals connected to the on-chip xbus) control their associated io pins directly via separate control lines. if an alternate input function of a pin is used, the direction of the pin must be programmed for input (dpx.y= ? 0 ? ) if an external device is driving the pin. the input direction is the default after reset. if no external device is connected to the pin, however, one can also set the direction for this pin to output. in this case, the pin reflects the state of the port output latch. thus, the alternate input function reads the value stored in the port output latch. this can be used for testing purposes to allow a software trigger of an alternate input function by writing to the port output latch. table 7-1 summary of alternate port functions port alternate function(s) alternate signal(s) port0 address and data lines when accessing external resources (e.g. memory) ad15 ... ad0, d15 ... d0, a15 ... a8 port1 address lines when accessing external resources (e.g. memory) a15 ... a0 port 2 fast external interrupt inputs ex7in ... ex0in port 3 system clock or programmable frequ. output optional bus control signal input/output functions of timers, serial interfaces clkout/fout, bhe /wrh , rxd0, txd0, mtsr, mrst, sclk, t2in, t3in, t4in, t3eud, t3out, capin, sda0, scl0 port 4 selected segment address lines in systems with more than 64 kbytes of ext. resources a22 ... a16 port 5 analog input channels to the a/d converter timer control signal inputs an3 ... an0, t2eud, t4eud port 6 chip select output signals i 2 c interface lines cs4 ... cs0 , sda1, scl1, sda2
   user ? s manual 7-8 1999-08  on most of the port lines, the user software is responsible for setting the proper direction when using an alternate input or output function of a pin. this is done by setting or clearing the direction control bit dpx.y of the pin before enabling the alternate function. there are port lines, however, where the direction of the port line is switched automatically. for instance, in the multiplexed external bus modes of port0, the direction must be switched several times for an instruction fetch in order to output the addresses and to input the data. obviously, this cannot be done through instructions. in these cases, the direction of the port line is switched automatically by hardware if the alternate function of such a pin is enabled. to determine the appropriate level of the port output latches check how the alternate data output is combined with the respective port latch output. there is one basic structure for all port lines with only an alternate input function. port lines with only an alternate output function, however, have different structures due to the way the direction of the pin is switched and depending on whether the pin is accessible by the user software or not in the alternate function mode. all port lines that are not used for these alternate functions may be used as general purpose io lines. when using port pins for general purpose output, the initial output value should be written to the port latch prior to enabling the output drivers, in order to avoid undesired transitions on the output pins. this applies to single pins as well as to pin groups (see examples below). output_enable_single_pin: bset p4.0 ;initial output level is ? high ? bset dp4.0 ;switch on the output driver output_enable_pin_group: bfldl p4, #05h, #05h ;initial output level is ? high ? bfldl dp4, #05h, #05h ;switch on the output drivers note: when using several bset pairs to control more pins of one port, these pairs must be separated by instructions, which do not reference the respective port (see ? particular pipeline effects ? in chapter ? the central processing unit ? ). each of these ports and the alternate input and output functions are described in detail in the following subsections.
   user ? s manual 7-9 1999-08  7.4 port0 the two 8-bit ports p0h and p0l represent the higher and lower part of port0, respectively. both halfs of port0 can be written (e.g. via a pec transfer) without effecting the other half. if this port is used for general purpose io, the direction of each line can be configured via the corresponding direction registers dp0h and dp0l. p0l port0 low register sfr (ff00 h /80 h reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p0l .7 p0l .6 p0l .5 p0l .4 p0l .3 p0l .2 p0l .1 p0l .0 - - - - - - - - rw rw rw rw rw rw rw rw p0h port0 high register sfr (ff02 h /81 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p0h .7 p0h .6 p0h .5 p0h .4 p0h .3 p0h .2 p0h .1 p0h .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p0x.y port data register p0h or p0l bit y dp0l p0l direction ctrl. register esfr (f100 h /80 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dp0l .7 dp0l .6 dp0l .5 dp0l .4 dp0l .3 dp0l .2 dp0l .1 dp0l .0 - - - - - - - - rw rw rw rw rw rw rw rw dp0h p0h direction ctrl. register esfr (f102 h /81 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dp0h .7 dp0h .6 dp0h .5 dp0h .4 dp0h .3 dp0h .2 dp0h .1 dp0h .0 - - - - - - - - rw rw rw rw rw rw rw rw
   user ? s manual 7-10 1999-08  alternate functions of port0 when an external bus is enabled, port0 is used as data bus or address/data bus. note that an external 8-bit demultiplexed bus only uses p0l, while p0h is free for io (provided that no other bus mode is enabled). port0 is also used to select the system startup configuration. during reset, port0 is configured to input, and each line is held high through an internal pullup device. each line can now be individually pulled to a low level (see dc-level specifications in the respective data sheets) through an external pulldown device. a default configuration is selected when the respective port0 lines are at a high level. through pulling individual lines to a low level, this default can be changed according to the needs of the applications. the internal pullup devices are designed such that an external pulldown resistors (see data sheet specification) can be used to apply a correct low level. these external pulldown resistors can remain connected to the port0 pins also during normal operation, however, care has to be taken such that they do not disturb the normal function of port0 (this might be the case, for example, if the external resistor is too strong). with the end of reset, the selected bus configuration will be written to the buscon0 register. the configuration of the high byte of port0 will be copied into the special register rp0h. this read-only register holds the selection for the number of chip selects and segment addresses. software can read this register in order to react according to the selected configuration, if required. when the reset is terminated, the internal pullup devices are switched off, and port0 will be switched to the appropriate operating mode. during external accesses in multiplexed bus modes port0 first outputs the 16-bit intra- segment address as an alternate output function. port0 is then switched to high- impedance input mode to read the incoming instruction or data. in 8-bit data bus mode, two memory cycles are required for word accesses, the first for the low byte and the second for the high byte of the word. during write cycles port0 outputs the data byte or word after outputting the address. during external accesses in demultiplexed bus modes port0 reads the incoming instruction or data word or outputs the data byte or word. bit function dp0x.y port direction register dp0h or dp0l bit y dp0x.y = 0: port line p0x.y is an input (high-impedance) dp0x.y = 1: port line p0x.y is an output
   user ? s manual 7-11 1999-08  figure 7-6 port0 io and alternate functions when an external bus mode is enabled, the direction of the port pin and the loading of data into the port output latch are controlled by the bus controller hardware. the input of the port output latch is disconnected from the internal bus and is switched to the line labeled ? alternate data output ? via a multiplexer. the alternate data can be the 16-bit intrasegment address or the 8/16-bit data information. the incoming data on port0 is read on the line ? alternate data input ? . while an external bus mode is enabled, the user software should not write to the port output latch, otherwise unpredictable results may occur. when the external bus modes are disabled, the contents of the direction register last written by the user becomes active. p0h.7 p0h.6 p0h.5 p0h.4 p0h.3 p0h.2 p0h.1 p0h.0 p0l.7 p0l.6 p0l.5 p0l.4 p0l.3 p0l.2 p0l.1 p0l.0 port0 d7 d6 d5 d4 d3 d2 d1 d0 p0h p0l d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0 a15 a14 a13 a12 a11 a10 a9 a8 ad7 ad6 ad5 ad4 ad3 ad2 ad1 ad0 ad15 ad14 ad13 ad12 ad11 ad10 ad9 ad8 ad7 ad6 ad5 ad4 ad3 ad2 ad1 ad0 alternate function a) b) c) d) general purpose input/output 8-bit demux bus 16-bit demux bus 8-bit mux bus 16-bit mux bus
   user ? s manual 7-12 1999-08  the figure below shows the structure of a port0 pin. figure 7-7 block diagram of a port0 pin port output latch 0 1 0 1 driver clock pin direction latch 0 1 input latch internal bus altdatain altdataout alten altdir read write read write port0_1.vsd p0h.7-0, p0l.7-0
   user ? s manual 7-13 1999-08  7.5 port1 the two 8-bit ports p1h and p1l represent the higher and lower part of port1, respectively. both halfs of port1 can be written (e.g. via a pec transfer) without effecting the other half. if this port is used for general purpose io, the direction of each line can be configured via the corresponding direction registers dp1h and dp1l. p1l port1 low register sfr (ff04 h /82 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p1l .7 p1l 6 p1l .5 p1l .4 p1l .3 p1l .2 p1l .1 p1l .0 - - - - - - - - rw rw rw rw rw rw rw rw p1h port1 high register sfr (ff06 h /83 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p1h .7 p1h .6 p1h .5 p1h .4 p1h .3 p1h .2 p1h .1 p1h .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p1x.y port data register p1h or p1l bit y dp1l p1l direction ctrl. register esfr (f104 h /82 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dp1 l.7 dp1 l.6 dp1 l.5 dp1 l.4 dp1 l.3 dp1 l.2 dp1 l.1 dp1 l.0 - - - - - - - - rw rw rw rw rw rw rw rw dp1h p1h direction ctrl. register esfr (f106 h /83 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dp1 h.7 dp1 h.6 dp1 h.5 dp1 h.4 dp1 h.3 dp1 h.2 dp1 h.1 dp1 h.0 - - - - - - - - rw rw rw rw rw rw rw rw
   user ? s manual 7-14 1999-08  alternate functions of port1 when a demultiplexed external bus is enabled, port1 is used as address bus. note that demultiplexed bus modes use port1 as a 16-bit port. otherwise all 16 port lines can be used for general purpose io. during external accesses in demultiplexed bus modes port1 outputs the 16-bit intra- segment address as an alternate output function. during external accesses in multiplexed bus modes, when no buscon register selects a demultiplexed bus mode, port1 is not used and is available for general purpose io. figure 7-8 port1 io and alternate functions when an external bus mode is enabled, the direction of the port pin and the loading of data into the port output latch are controlled by the bus controller hardware. the input of the port output latch is disconnected from the internal bus and is switched to the line labeled ? alternate data output ? via a multiplexer. the alternate data is the 16-bit intrasegment address. while an external bus mode is enabled, the user software should not write to the port output latch, otherwise unpredictable results may occur. when the external bus modes are disabled, the contents of the direction register last written by the user becomes active. bit function dp1x.y port direction register dp1h or dp1l bit y dp1x.y = 0: port line p1x.y is an input (high-impedance) dp1x.y = 1: port line p1x.y is an output p1h.7 p1h.6 p1h.5 p1h.4 p1h.3 p1h.2 p1h.1 p1h.0 p1l.7 p1l.6 p1l.5 p1l.4 p1l.3 p1l.2 p1l.1 p1l.0 port1 p1h p1l a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 alternate function general purpose input/output 8/16-bit demux bus
   user ? s manual 7-15 1999-08  the figure below shows the structure of a port1 pin. figure 7-9 block diagram of a port1 pin with address function p1h.7-0, p1l.7-0 port output latch 0 1 0 1 driver clock pin direction latch 0 1 input latch internal bus altdataout alten altdir = ? 1 ? read write read write port1_1.vsd
   user ? s manual 7-16 1999-08  7.6 port 2 if this 8-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp2. each port line can be switched into push/pull or open drain mode via the open drain control register odp2. p2  '()  sfr (ffc0 h /e0 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p2 .15 p2 .14 p2 .13 p2 .12 p2 .11 p2 .10 p2 .9 p2 .8 rw rw rw rw rw rw rw rw - - - - - - - - bit function p2.y port data register p2 bit y dp2 p2 direction ctrl. register sfr (ffc2 h /e1 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dp2 .15 dp2 .14 dp2 .13 dp2 .12 dp2 .11 dp2 .10 dp2 .9 dp2 .8 rw rw rw rw rw rw rw rw - - - - - - - - bit function dp2.y port direction register dp2 bit y dp2.y = 0: port line p2.y is an input (high-impedance) dp2.y = 1: port line p2.y is an output odp2 '!( *)* esfr (f1c2 h /e1 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 odp 2.15 odp 2.14 odp 2.13 odp 2.12 odp 2.11 odp 2.10 odp 2.9 odp 2.8 rw rw rw rw rw rw rw rw - - - - - - - - bit function odp2.y port 2 open drain control register bit y odp2.y = 0: port line p2.y output driver in push/pull mode odp2.y = 1: port line p2.y output driver in open drain mode
   user ? s manual 7-17 1999-08  alternate functions of port 2 all port 2 lines (p2.15 ... p2.8) serve as external interrupt inputs ex7in...ex0in (16 tcl sample rate). the table below summarizes the alternate functions of port 2. figure 7-10 port 2 io and alternate functions table 7-2 alternate functions of port 2 port 2 pin alternate function p2.8 p2.9 p2.10 p2.11 p2.12 p2.13 p2.14 p2.15 ex0in fast external interrupt 0 input ex1in fast external interrupt 1 input ex2in fast external interrupt 2 input ex3in fast external interrupt 3 input ex4in fast external interrupt 4 input ex5in fast external interrupt 5 input ex6in fast external interrupt 6 input ex7in fast external interrupt 7 input p2.15 p2.14 p2.13 p2.12 p2.11 p2.10 p2.9 p2.8 port 2 alternate function general purpose input/output ex7in ex6in ex5in ex4in ex3in ex2in ex1in ex0in fast external interrupt input
   user ? s manual 7-18 1999-08  figure 7-11 block diagram of a port 2 pin p2.15-8, z = 7-0 port output latch driver clock pin direction latch open drain latch 0 1 input latch internal bus exzin read write read write read write port2_2.vsd
   user ? s manual 7-19 1999-08  7.7 port 3 if this 15-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp3. most port lines can be switched into push/pull or open drain mode via the open drain control register odp3. p3  +()  sfr (ffc4 h /e2 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p3 .15 - p3 .13 p3 .12 p3 .11 p3 .10 p3.9 p3.8 p3.7 p3.6 p3.5 p3.4 p3.3 p3.2 p3.1 p3.0 rw - rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function p3.y port data register p3 bit y dp3 p3 direction ctrl. register sfr (ffc6 h /e3 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dp3 .15 - dp3 .13 dp3 .12 dp3 .11 dp3 .10 dp3 .9 dp3 .8 dp3 .7 dp3 .6 dp3 .5 dp3 .4 dp3 .3 dp3 .2 dp3 .1 dp3 .0 rw - rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function dp3.y port direction register dp3 bit y dp3.y = 0: port line p3.y is an input (high-impedance) dp3.y = 1: port line p3.y is an output odp3 +!( *)* esfr (f1c6 h /e3 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -- odp 3 .13 - odp 3 .11 odp 3 .10 odp 3 .9 odp 3 .8 odp 3 .7 odp 3 .6 odp 3 .5 odp 3 .4 odp 3 .3 odp 3 .2 -- - - rw - rw rw rw rw rw rw rw rw rw rw - - bit function odp3.y port 3 open drain control register bit y odp3.y = 0: port line p3.y output driver in push/pull mode odp3.y = 1: port line p3.y output driver in open drain mode
   user ? s manual 7-20 1999-08  note: due to pin limitations register bit p3.14 is not connected to an io pin. pins p3.15 and p3.12 do not support open drain mode. pins p3.1 and p3.0 provide open-drain-only drivers. alternate functions of port 3 the pins of port 3 serve for various functions which include external timer control lines, the two serial interfaces, one i 2 c bus interface and the control lines bhe /wrh and clkout/fout. the table below summarizes the alternate functions of port 3. table 7-3 alternate functions of port 3 port 3 pin alternate function p3.0 p3.1 p3.2 p3.3 p3.4 p3.5 p3.6 p3.7 p3.8 p3.9 p3.10 p3.11 p3.12 p3.13 - p3.15 scl0 i2c bus clock line 0 (open drain only) sda0 i2c bus data line 0 (open drain only) capin gpt2 capture input t3out timer 3 toggle latch output t3eud timer 3 external up/down input t4in timer 4 count input t3in timer 3 count input t2in timer 2 count input mrst ssc master receive / slave transmit mtsr ssc master transmit / slave receive txd0 asc0 transmit data output rxd0 asc0 receive data input bhe/wrh byte high enable / write high output sclk ssc shift clock input/output - clkout/fout system clock output / programmable frequency output
   user ? s manual 7-21 1999-08  figure 7-12 port 3 io and alternate functions the port structure of the port 3 pins depends on their alt. func. (see figure below). when the on-chip peripheral associated with a port 3 pin is configured to use the alternate input function, it reads the input latch, which represents the state of the pin, via the line labeled ? alternate data input ? . port 3 pins with alternate input functions are: t2in, t3in, t4in, t3eud and capin. when the on-chip peripheral associated with a port 3 pin is configured to use the alternate output function, its ? alternate data output ? line is anded with the port output latch line. when using these alternate functions, the user must set the direction of the port line to output (dp3.y=1) and must set the port output latch (p3.y=1). otherwise the pin is in its high-impedance state (when configured as input) or the pin is stuck at '0' (when the port output latch is cleared). when the alternate output functions are not used, the ? alternate data output ? line is in its inactive state, which is a high level ('1'). port 3 pins with alternate output functions are: t3out, txd0 and clkout/fout. when the on-chip peripheral associated with a port 3 pin is configured to use both the alternate input and output function, the descriptions above apply to the respective current operating mode. the direction must be set accordingly. port 3 pins with alternate input/output functions are: scl0, sda0, mtsr, mrst, rxd0 and sclk. note: enabling the clkout function automatically enables the p3.15 output driver. setting bit dp3.15= ? 1 ? is not required. the clkout function is automatically enabled in emulation mode. pins p3.0 and p3.1 provide open drain output drivers only in order to be compatible with the i2c bus specification. p3.15 p3.13 p3.12 p3.11 p3.10 p3.9 p3.8 p3.7 p3.6 p3.5 p3.4 p3.3 p3.2 p3.1 p3.0 port 3 no pin clkout sclk bhe rxd0 txd0 mtsr mrst t2in t3in t4in t3eud t3out capin sda0 scl0 fout wrh alternate function a) b) general purpose input/output
   user ? s manual 7-22 1999-08  figure 7-13 block diagram of a port 3 pin with alternate input or alternate output function p3.13, p3.11-0 port output latch & driver clock pin direction latch open drain latch 0 1 input latch internal bus altdatain altdataout read write read write read write port3_1.vsd
   user ? s manual 7-23 1999-08  pin p3.12 (bhe /wrh ) is one more pin with an alternate output function. however, its structure is slightly different (see figure below), because after reset the bhe or wrh function must be used depending on the system startup configuration. in these cases there is no possibility to program any port latches before. thus the appropriate alternate function is selected automatically. if bhe /wrh is not used in the system, this pin can be used for general purpose io by disabling the alternate function (bytdis = ? 1 ? / wrcfg= ? 0 ? ). figure 7-14 block diagram of pins p3.15 (clkout/fout) and p3.12 (bhe /wrh ) note: enabling the bhe or wrh function automatically enables the p3.12 output driver. setting bit dp3.12= ? 1 ? is not required. enabling the clkout function automatically enables the p3.15 output driver. setting bit dp3.15= ? 1 ? is not required. port output latch 0 1 0 1 driver clock pin direction latch 0 1 input latch internal bus altdataout alten altdir = ? 1 ? read write read write port3_2.vsd p3.15, p3.12
   user ? s manual 7-24 1999-08  7.8 port 4 if this 7-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp4. alternate functions of port 4 during external bus cycles that use segmentation (i.e. an address space above 64 kbyte) a number of port 4 pins may output the segment address lines. the number of pins that is used for segment address output determines the external address space which is directly accessible. the other pins of port 4 (if any) may be used for general purpose io. if segment address lines are selected, the alternate function of port 4 may be necessary to access e.g. external memory directly after reset. for this reason port 4 will be switched to this alternate function automatically. p4  ,()  sfr (ffc8 h /e4 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - p4.6 p4.5 p4.4 p4.3 p4.2 p4.1 p4.0 - - - - - - - - - rw rw rw rw rw rw rw bit function p4.y port data register p4 bit y dp4 p4 direction ctrl. register sfr (ffca h /e5 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - dp4 .6 dp4 .5 dp4 .4 dp4 .3 dp4 .2 dp4 .1 dp4 .0 - - - - - - - - - rw rw rw rw rw rw rw bit function dp4.y port direction register dp4 bit y dp4.y = 0: port line p4.y is an input (high-impedance) dp4.y = 1: port line p4.y is an output
   user ? s manual 7-25 1999-08  the number of segment address lines is selected via port0 during reset. the selected value can be read from bitfield salsel in register rp0h (read only) e.g. in order to check the configuration during run time. the table below summarizes the alternate functions of port 4 depending on the number of selected segment address lines (coded via bitfield salsel). figure 7-15 port 4 io and alternate functions table 7-4 alternate functions of port 4 port 4 pin std. function salsel=01 64 kb altern. function salsel=11 256kb altern. function salsel=00 1 mb altern. function salsel=10 8 mb p4.0 p4.1 p4.2 p4.3 p4.4 p4.5 p4.6 p4.7 gen. purpose io gen. purpose io gen. purpose io gen. purpose io gen. purpose io gen. purpose io gen. purpose io - seg. address a16 seg. address a17 gen. purpose io gen. purpose io gen. purpose io gen. purpose io gen. purpose io - seg. address a16 seg. address a17 seg. address a18 seg. address a19 gen. purpose io gen. purpose io gen. purpose io - seg. address a16 seg. address a17 seg. address a18 seg. address a19 seg. address a20 seg. address a21 seg. address a22 - - - - - - - - - - p4.6 p4.5 p4.4 p4.3 p4.2 p4.1 p4.0 port 4 a22 a21 a20 a19 a18 a17 a16 alternate function a) general purpose input/output
   user ? s manual 7-26 1999-08  figure 7-16 block diagram of a port 4 pin p4.6-0 port output latch 0 1 0 1 driver clock pin direction latch 0 1 input latch internal bus altdatain altdataout alten altdir read write read write port4_2.vsd
   user ? s manual 7-27 1999-08  7.9 port 5 this 6-bit input port can only read data. there is no output latch and no direction register. data written to p5 will be lost. alternate functions of port 5 four lines of port 5 are also connected to the input multiplexer of the analog/digital converter. these port lines can accept analog signals (anx) that can be converted by the adc. for pins that shall be used as analog inputs it is recommended to disable the digital input stage via register p5didis (see description below). this avoids undesired cross currents and switching noise while the (analog) input signal level is between vil and vih. some pins of port 5 also serve as external gpt timer control lines. the table below summarizes the alternate functions of port 5. p5  -()  sfr (ffa2 h /d1 h ) reset value: xxxx h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p5 .15 p5 .14 p5.3 p5.2 p5.1 p5.0 r r - - - - - - - - - - r r r r bit function p5.y port data register p5 bit y (read only) read as ? 1 ? if the digital input stage is disabled via p5didis.y = ? 1 ? . table 7-5 alternate functions of port 5 port 5 pin alternate function a) alternate function b) p5.0 p5.1 p5.2 p5.3 p5.14 p5.15 analog input an0 analog input an1 analog input an2 analog input an3 - - - - t4eud timer 4 ext. up/down input t2eud timer 2 ext. up/down input
   user ? s manual 7-28 1999-08  figure 7-17 port 5 io and alternate functions port 5 digital input control port 5 pins may be used for both digital an analog input. by setting the respective bit in register p5didis the digital input stage of the respective port 5 pin can be disconnected from the pin. this is recommended when the pin is to be used as analog input, as it reduces the current through the digital input stage and prevents it from toggling while the (analog) input level is between the digital low and high thresholds. so the consumed power and the generated noise can be reduced. after reset all digital input stages are enabled. p5didis p5 dig. inp. disable reg. sfr (ffa4 h /d2 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p5d .3 p5d .2 p5d .1 p5d .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p5d.y port p5 bit y digital input control 0: digital input stage connected to port line p5.y 1: digital input stage disconnected from port line p5.y when being read or used as alternate input this line appears as ? 1 ? . p5.15 p5.14 p5.3 p5.2 p5.1 p5.0 port 5 an3 an2 an1 an0 alternate function a) general purpose input t2eud t4eud b) a/d converter input timer control input
   user ? s manual 7-29 1999-08  port 5 pins have a special port structure (see figure below), first because it is an input only port, and second because the analog input channels are directly connected to the pins rather than to the input latches. figure 7-18 block diagram of a port 5 pin note: the lines ? altdatain ? and ? analoginput ? do not exist on all port 5 inputs. p5.15-14, p5.3-0 clock pin input latch internal bus altdatain read port5_1.vsd diginputen channelselect analoginput
   user ? s manual 7-30 1999-08  7.10 port 6 if this 8-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp6. lines p6.4-0 can be switched into push/pull or open drain mode via the open drain control register odp6. p6  ()  sfr (ffcc h /e6 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 p6.7 p6.6 p6.5 p6.4 p6.3 p6.2 p6.1 p6.0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p6.y port data register p6 bit y dp6 p6 direction ctrl. register sfr (ffce h /e7 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dp6 .7 dp6 .6 dp6 .5 dp6 .4 dp6 .3 dp6 .2 dp6 .1 dp6 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function dp6.y port direction register dp6 bit y dp6.y = 0: port line p6.y is an input (high-impedance) dp6.y = 1: port line p6.y is an output odp6 !( *)* esfr (f1ce h /e7 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 --- odp6 .4 odp6 .3 odp6 .2 odp6 .1 odp6 .0 - - - - - - - - - - - rw rw rw rw rw bit function odp6.y port 6 open drain control register bit y odp6.y = 0: port line p6.y output driver in push/pull mode odp6.y = 1: port line p6.y output driver in open drain mode
   user ? s manual 7-31 1999-08  alternate functions of port 6 a programmable number of chip select signals (cs4...cs0) derived from the bus control registers (buscon4...buscon0) can be output on 5 pins of port 6. the other 3 pins may be used for i 2 c bus interface lines. the number of chip select signals is selected via port0 during reset. the selected value can be read from bitfield cssel in register rp0h (read only) e.g. in order to check the configuration during run time. the table below summarizes the alternate functions of port 6 depending on the number of selected chip select lines (coded via bitfield cssel). figure 7-19 port 6 io and alternate functions table 7-6 alternate functions of port 6 port 6 pin altern. function cssel = 10 altern. function cssel = 01 altern. function cssel = 00 altern. function cssel = 11 p6.0 p6.1 p6.2 p6.3 p6.4 gen. purpose io gen. purpose io gen. purpose io gen. purpose io gen. purpose io chip select cs0 chip select cs1 gen. purpose io gen. purpose io gen. purpose io chip select cs0 chip select cs1 chip select cs2 gen. purpose io gen. purpose io chip select cs0 chip select cs1 chip select cs2 chip select cs3 chip select cs4 p6.5 p6.6 p6.7 sda1 i 2 c bus data line 1 scl1 i 2 c bus clock line 1 sda2 i 2 c bus data line 2 - - - - - - - - p6.7 p6.6 p6.5 p6.4 p6.3 p6.2 p6.1 p6.0 port 6 - - - - - - - - sda2 scl1 sda1 cs4 cs3 cs2 cs1 cs0 alternate function a) general purpose input/output
   user ? s manual 7-32 1999-08  the chip select lines of port 6 additionally have an internal weak pullup device. this device is switched on always during reset for all potential cs output pins. this feature is implemented to drive the chip select lines high during reset in order to avoid multiple chip selection. after reset the cs function must be used, if selected so. in this case there is no possibility to program any port latches before. thus the alternate function (cs ) is selected automatically in this case. note: the open drain output option can only be selected via software earliest during the initialization routine; the configured chip select lines (via cssel) will be in push/ pull output driver mode directly after reset. figure 7-20 block diagram of port 6 pins with an alternate output function p6.4-0 port output latch 0 1 0 1 driver clock pin direction latch open drain latch 0 1 input latch internal bus altdataout alten altdir = ? 1 ? read write read write read write port6_1.vsd
   user ? s manual 7-33 1999-08  figure 7-21 block diagram of port 6 pins with an alternate input and output function port output latch 0 1 0 1 driver clock pin direction latch 0 1 input latch internal bus altdatain altdataout alten altdir read write read write port6_4.vsd p6.7-5
   user ? s manual 7-34 1999-08 
 (

  user ? s manual 8-1 1999-08  8 dedicated pins most of the input/output or control signals of the functional the c161pi are realized as alternate functions of pins of the parallel ports. there is, however, a number of signals that use separate pins, including the oscillator, special control signals and, of course, the power supply. the table below summarizes the 24 dedicated pins of the c161pi. the address latch enable signal ale controls external address latches that provide a stable address in multiplexed bus modes. ale is activated for every external bus cycle independent of the selected bus mode, i.e. it is also activated for bus cycles with a demultiplexed address bus. when an external bus is enabled (one or more of the busact bits set) also x-peripheral accesses will generate an active ale signal. ale is not activated for internal accesses, i.e. accesses to rom/otp/flash (if provided), the internal ram and the special function registers. in single chip mode, i.e. when no external bus is enabled (no busact bit set), ale will also remain inactive for x- peripheral accesses. during reset an internal pulldown ensures an inactive (low) level on the ale output. table 8-1 c161pi dedicated pins pin(s) function ale address latch enable rd external read strobe wr /wrl external write/write low strobe ready ready input ea external access enable nmi non-maskable interrupt input xtal1, xtal2 oscillator input / output rstin reset input rstout reset output varef, vagnd power supply for analog/digital converter vdd, vss digital power supply and ground ( 6 pins each )
 (

  user ? s manual 8-2 1999-08  the external read strobe rd controls the output drivers of external memory or peripherals when the c161pi reads data from these external devices. during accesses to on-chip x-peripherals rd remains inactive (high). during reset an internal pullup ensures an inactive (high) level on the rd output. the external write strobe wr /wrl controls the data transfer from the c161pi to an external memory or peripheral device. this pin may either provide an general wr signal activated for both byte and word write accesses, or specifically control the low byte of an external 16-bit device (wrl ) together with the signal wrh (alternate function of p3.12/ bhe ). during accesses to on-chip x-peripherals wr /wrl remains inactive (high). during reset an internal pullup ensures an inactive (high) level on the wr /wrl output. the ready input ready receives a control signal from an external memory or peripheral device that is used to terminate an external bus cycle, provided that this function is enabled for the current bus cycle. ready may be used as synchronous ready or may be evaluated asynchronously. when waitstates are defined for a ready controlled address window the ready input is not evaluated during these waitstates. an internal pullup ensures an inactive (high) level on the ready input. the external access enable pin ea determines if the c161pi after reset starts fetching code from the internal rom area (ea = ? 1 ? ) or via the external bus interface (ea = ? 0 ? ). be sure to hold this input low for romless devices. at the end of the internal reset sequence the ea signal is latched together with the port0 configuration. the non-maskable interrupt input nmi allows to trigger a high priority trap via an external signal (e.g. a power-fail signal). it also serves to validate the pwrdn instruction that switches the c161pi into power-down mode. the nmi pin is sampled with every cpu clock cycle to detect transitions. the oscillator input xtal1 and output xtal2 connect the internal pierce oscillator to the external crystal. the oscillator provides an inverter and a feedback element. the standard external oscillator circuitry (see chapter ? clock generation ? ) comprises the crystal, two low end capacitors and series resistor to limit the current through the crystal. an external clock signal may be fed to the input xtal1, leaving xtal2 open or terminating it for higher input frequencies.
 (

  user ? s manual 8-3 1999-08  the reset input rstin allows to put the c161pi into the well defined reset condition either at power-up or external events like a hardware failure or manual reset. the input voltage threshold of the rstin pin is raised compared to the standard pins in order to minimize the noise sensitivity of the reset input. in bidirectional reset mode the c161pi ? s line rstin may be be driven active by the chip logic e.g. in order to support external equipment which is required for startup (e.g. flash memory). bidirectional reset reflects internal reset sources (software, watchdog) also to the rstin pin and converts short hardware reset pulses to a minimum duration of the internal reset sequence. bidirectional reset is enabled by setting bit bdrsten in register syscon and changes rstin from a pure input to an open drain io line. when an internal reset is triggered by the srst instruction or by a watchdog timer overflow or a low level is applied to the rstin line, an internal driver pulls it low for the duration of the internal reset sequence. after that it is released and is then controlled by the external circuitry alone. the bidirectional reset function is useful in applications where external devices require a defined reset signal but cannot be connected to the c161pi ? s rstout signal, e.g. an external flash memory which must come out of reset and deliver code well before rstout can be deactivated via einit. the following behaviour differences must be observed when using the bidirectional reset feature in an application:  bit bdrsten in register syscon cannot be changed after einit and is cleared automatically after a reset.  the reset indication flags always indicate a long hardware reset.  the port0 configuration is treated like on a hardware reset. especially the bootstrap loader may be activated when p0l.4 is low.  pin rstin may only be connected to external reset devices with an open drain output driver.  a short hardware reset is extended to the duration of the internal reset sequence. the reset output rstout provides a special reset signal for external circuitry. rstout is activated at the beginning of the reset sequence, triggered via rstin , a watchdog timer overflow or by the srst instruction. rstout remains active (low) until the einit instruction is executed. this allows to initialize the controller before the external circuitry is activated. note: during emulation mode pin rstout is used as an input and therefore must be driven by the external circuitry.
 (

  user ? s manual 8-4 1999-08  the power supply pins for the analog/digital converter varef and vagnd provide a separate power supply for the on-chip adc. this reduces the noise that is coupled to the analog input signals from the digital logic sections and so improves the stability of the conversion results, when varef and vagnd are properly discoupled from vdd and vss. the power supply pins vdd and vss provide the power supply for the digital logic of the c161pi. the respective vdd/vss pairs should be decoupled as close to the pins as possible. for best results it is recommended to implement two-level decoupling, e.g. (the widely used) 100 nf in parallel with 30...40 pf capacitors which deliver the peak currents. note: all vdd pins and all vss pins must be connected to the power supply and ground, respectively.
 ./0 1  user ? s manual 9-1 1999-08  9 the external bus interface although the c161pi provides a powerful set of on-chip peripherals and on-chip ram and rom/otp/flash (except for romless versions) areas, these internal units only cover a small fraction of its address space of up to 16 mbyte. the external bus interface allows to access external peripherals and additional volatile and non-volatile memory. the external bus interface provides a number of configurations, so it can be taylored to fit perfectly into a given application system. figure 9-1 sfrs and port pins associated with the external bus interface accesses to external memory or peripherals are executed by the integrated external bus controller (ebc). the function of the ebc is controlled via the syscon register and the busconx and addrselx registers. the busconx registers specify the external bus cycles in terms of data width (16-bit/8-bit), chip selects and length (waitstates / ale / rw delay). these parameters are used for accesses within a specific address area which is defined via the corresponding register addrselx. the four pairs buscon1/addrsel1...buscon4/addrsel4 allow to define four independent ? address windows ? , while all external accesses outside these windows are controlled via register buscon0. p4 buscon0 buscon1 buscon2 addrsel4 p0l / p0h addrsel1 syscon addrselxaddress range select register 1...4 busconx bus mode control register 0...4 syscon system control register rp0h port p0h reset configuration register ports & direction control alternate functions address registers mode registers control registers buscon3 buscon4 addrsel2 rp0h dp3 p3 addrsel3 p1l / p1h p6 odp6e dp6 port0 ea port1 rstin ale ready rd wr /wrl bhe /wrh p0l/p0h port0 data registers p1l/p1h port1 data registers dp3 port 3 direction control register p3 port 3 data register p4 port 4 data register odp6 port 6 open drain control register dp6 port 6 direction control register p6 port 6 data register
 ./0 1  user ? s manual 9-2 1999-08  9.1 single chip mode single chip mode is entered, when pin ea is high during reset. in this case register buscon0 is initialized with 0000 h , which also resets bit busact0, so no external bus is enabled. in single chip mode the c161pi operates only with and out of internal resources. no external bus is configured and no external peripherals and/or memory can be accessed. also no port lines are occupied for the bus interface. when running in single chip mode, however, external access may be enabled by configuring an external bus under software control. single chip mode allows the c161pi to start execution out of the internal program memory (mask-rom, otp or flash memory). note: any attempt to access a location in the external memory space in single chip mode results in the hardware trap illbus.
 ./0 1  user ? s manual 9-3 1999-08  9.2 external bus modes when the external bus interface is enabled (bit busactx= ? 1 ? ) and configured (bitfield btyp), the c161pi uses a subset of its port lines together with some control lines to build the external bus. the bus configuration (btyp) for the address windows (buscon4...buscon1) is selected via software typically during the initialization of the system. the bus configuration (btyp) for the default address range (buscon0) is selected via port0 during reset, provided that pin ea is low during reset. otherwise buscon0 may be programmed via software just like the other buscon registers. the 16 mbyte address space of the c161pi is divided into 256 segments of 64 kbyte each. the 16-bit intra-segment address is output on port0 for multiplexed bus modes or on port1 for demultiplexed bus modes. when segmentation is disabled, only one 64 kbyte segment can be used and accessed. otherwise additional address lines may be output on port 4 (addressing up to 8mbyte ) and/or several chip select lines may be used to select different memory banks or peripherals. these functions are selected during reset via bitfields salsel and cssel of register rp0h, respectively. note: bit sgtdis of register syscon defines, if the csp register is saved during interrupt entry (segmentation active) or not (segmentation disabled). table 9-1 summary of external bus modes btyp encoding external data bus width external address bus mode 0 0 8-bit data demultiplexed addresses 0 1 8-bit data multiplexed addresses 1 0 16-bit data demultiplexed addresses 1 1 16-bit data multiplexed addresses
 ./0 1  user ? s manual 9-4 1999-08  multiplexed bus modes in the multiplexed bus modes the 16-bit intra-segment address as well as the data use port0. the address is time-multiplexed with the data and has to be latched externally. the width of the required latch depends on the selected data bus width, i.e. an 8-bit data bus requires a byte latch (the address bits a15...a8 on p0h do not change, while p0l multiplexes address and data), a 16-bit data bus requires a word latch (the least significant address line a0 is not relevant for word accesses). the upper address lines (an...a16) are permanently output on port 4 (if segmentation is enabled) and do not require latches. the ebc initiates an external access by generating the address latch enable signal (ale) and then placing an address on the bus. the falling edge of ale triggers an external latch to capture the address. after a period of time during which the address must have been latched externally, the address is removed from the bus. the ebc now activates the respective command signal (rd , wr , wrl , wrh ). data is driven onto the bus either by the ebc (for write cycles) or by the external memory/peripheral (for read cycles). after a period of time, which is determined by the access time of the memory/ peripheral, data become valid. read cycles: input data is latched and the command signal is now deactivated. this causes the accessed device to remove its data from the bus which is then tri-stated again. write cycles: the command signal is now deactivated. the data remain valid on the bus until the next external bus cycle is started. figure 9-2 multiplexed bus cycle
 ./0 1  user ? s manual 9-5 1999-08  demultiplexed bus modes in the demultiplexed bus modes the 16-bit intra-segment address is permanently output on port1, while the data uses port0 (16-bit data) or p0l (8-bit data). the upper address lines are permanently output on port 4 (if selected via salsel during reset). no address latches are required. the ebc initiates an external access by placing an address on the address bus. after a programmable period of time the ebc activates the respective command signal (rd , wr , wrl , wrh ). data is driven onto the data bus either by the ebc (for write cycles) or by the external memory/peripheral (for read cycles). after a period of time, which is determined by the access time of the memory/peripheral, data become valid. read cycles: input data is latched and the command signal is now deactivated. this causes the accessed device to remove its data from the data bus which is then tri-stated again. write cycles: the command signal is now deactivated. if a subsequent external bus cycle is required, the ebc places the respective address on the address bus. the data remain valid on the bus until the next external bus cycle is started. figure 9-3 demultiplexed bus cycle
 ./0 1  user ? s manual 9-6 1999-08  switching between the bus modes the ebc allows to switch between different bus modes dynamically, i.e. subsequent external bus cycles may be executed in different ways. certain address areas may use multiplexed or demultiplexed buses or use ready control or predefined waitstates. a change of the external bus characteristics can be initiated in two different ways: reprogramming the buscon and/or addrsel registers allows to either change the bus mode for a given address window, or change the size of an address window that uses a certain bus mode. reprogramming allows to use a great number of different address windows (more than buscons are available) on the expense of the overhead for changing the registers and keeping appropriate tables. switching between predefined address windows automatically selects the bus mode that is associated with the respective window. predefined address windows allow to use different bus modes without any overhead, but restrict their number to the number of buscons. however, as buscon0 controls all address areas, which are not covered by the other buscons, this allows to have gaps between these windows, which use the bus mode of buscon0. port1 will output the intra-segment address, when any of the buscon registers selects a demultiplexed bus mode, even if the current bus cycle uses a multiplexed bus mode. this allows to have an external address decoder connected to port1 only, while using it for all kinds of bus cycles. note: never change the configuration for an address area that currently supplies the instruction stream. due to the internal pipelining it is very difficult to determine the first instruction fetch that will use the new configuration. only change the configuration for address areas that are not currently accessed. this applies to buscon registers as well as to addrsel registers. the usage of the buscon/addrsel registers is controlled via the issued addresses. when an access (code fetch or data) is initiated, the respective generated physical address defines, if the access is made internally, uses one of the address windows defined by addrsel4...1, or uses the default configuration in buscon0. after initializing the active registers, they are selected and evaluated automatically by interpreting the physical address. no additional switching or selecting is necessary during run time, except when more than the four address windows plus the default is to be used. switching from demultiplexed to multiplexed bus mode represents a special case. the bus cycle is started by activating ale and driving the address to port 4 and port1 as usual, if another buscon register selects a demultiplexed bus. however, in the multiplexed bus modes the address is also required on port0. in this special case the address on port0 is delayed by one cpu clock cycle, which delays the complete (multiplexed) bus cycle and extends the corresponding ale signal (see figure below).
 ./0 1  user ? s manual 9-7 1999-08  this extra time is required to allow the previously selected device (via demultiplexed bus) to release the data bus, which would be available in a demultiplexed bus cycle. figure 9-4 switching from demultiplexed to multiplexed bus mode
 ./0 1  user ? s manual 9-8 1999-08  external data bus width the ebc can operate on 8-bit or 16-bit wide external memory/peripherals. a 16-bit data bus uses port0, while an 8-bit data bus only uses p0l, the lower byte of port0. this saves on address latches, bus transceivers, bus routing and memory cost on the expense of transfer time. the ebc can control word accesses on an 8-bit data bus as well as byte accesses on a 16-bit data bus. word accesses on an 8-bit data bus are automatically split into two subsequent byte accesses, where the low byte is accessed first, then the high byte. the assembly of bytes to words and the disassembly of words into bytes is handled by the ebc and is transparent to the cpu and the programmer. byte accesses on a 16-bit data bus require that the upper and lower half of the memory can be accessed individually. in this case the upper byte is selected with the bhe signal, while the lower byte is selected with the a0 signal. so the two bytes of the memory can be enabled independent from each other, or together when accessing words. when writing bytes to an external 16-bit device, which has a single cs input, but two wr enable inputs (for the two bytes), the ebc can directly generate these two write control signals. this saves the external combination of the wr signal with a0 or bhe . in this case pin wr serves as wrl (write low byte) and pin bhe serves as wrh (write high byte). bit wrcfg in register syscon selects the operating mode for pins wr and bhe . the respective byte will be written on both data bus halfs. when reading bytes from an external 16-bit device, whole words may be read and the c161pi automatically selects the byte to be input and discards the other. however, care must be taken when reading devices that change state when being read, like fifos, interrupt status registers, etc. in this case individual bytes should be selected using bhe and a0. note: port1 becomes available for general purpose io, when none of the buscon registers selects a demultiplexed bus mode. table 9-2 bus mode versus performance bus mode transfer rate ( speed factor for byte/word/dword access ) system requirements free io lines 8-bit multiplexed very low ( 1.5 / 3 / 6 ) low (8-bit latch, byte bus) p1h, p1l 8-bit demultipl. low ( 1 / 2 / 4 ) very low (no latch, byte bus) p0h 16-bit multiplexed high ( 1.5 / 1.5 / 3 ) high (16-bit latch, word bus) p1h, p1l 16-bit demultipl. very high ( 1 / 1 / 2 ) low (no latch, word bus) ---
 ./0 1  user ? s manual 9-9 1999-08  disable/enable control for pin bhe ( bytdis) bit bytdis is provided for controlling the active low byte high enable (bhe ) pin. the function of the bhe pin is enabled, if the bytdis bit contains a ? 0 ? . otherwise, it is disabled and the pin can be used as standard io pin. the bhe pin is implicitly used by the external bus controller to select one of two byte-organized memory chips, which are connected to the c161pi via a word-wide external data bus. after reset the bhe function is automatically enabled (bytdis = ? 0 ? ), if a 16-bit data bus is selected during reset, otherwise it is disabled (bytdis= ? 1 ? ). it may be disabled, if byte access to 16-bit memory is not required, and the bhe signal is not used. segment address generation during external accesses the ebc generates a (programmable) number of address lines on port 4, which extend the 16-bit address output on port0 or port1 and so increase the accessible address space. the number of segment address lines is selected during reset and coded in bit field salsel in register rp0h (see table below). note: the total accessible address space may be increased by accessing several banks which are distinguished by individual chip select lines. if port 4 is used to output segment address lines, in most cases the drivers must operate in push/pull mode. make sure that opd4 does not select open drain mode in this case. table 9-3 decoding of segment address lines salsel segment address lines directly accessible address space 1 1 two: a17...a16 256 kbyte (default without pull-downs) 1 0 seven: a22...a16 8 mbyte (maximum) 0 1 none 64 kbyte (minimum) 0 0 four: a19...a16 1 mbyte
 ./0 1  user ? s manual 9-10 1999-08  cs signal generation during external accesses the ebc can generate a (programmable) number of cs lines on port 6, which allow to directly select external peripherals or memory banks without requiring an external decoder. the number of cs lines is selected during reset and coded in bit field cssel in register rp0h (see table below). the csx outputs are associated with the busconx registers and are driven active (low) for any access within the address area defined for the respective buscon register. for any access outside this defined address area the respective csx signal will go inactive (high). at the beginning of each external bus cycle the corresponding valid cs signal is determined and activated. all other cs lines are deactivated (driven high) at the same time. note: the csx signals will not be updated for an access to any internal address area (i.e. when no external bus cycle is started), even if this area is covered by the respective addrselx register. an access to an on-chip x-peripheral deactivates all external cs signals. upon accesses to address windows without a selected cs line all selected cs lines are deactivated. the chip select signals allow to be operated in four different modes (see table below) which are selected via bits cswenx and csrenx in the respective busconx register. table 9-4 decoding of chip select lines cssel chip select lines note 1 1 five: cs4 ...cs0 default without pull-downs 1 0 none port 6 pins free for io 0 1 two: cs1 ...cs0 0 0 three: cs2 ...cs0 table 9-5 chip select generation modes cswenx csrenx chip select mode 0 0 address chip select (default after reset) 0 1 read chip select 1 0 write chip select 1 1 read/write chip select
 ./0 1  user ? s manual 9-11 1999-08  read or write chip select signals remain active only as long as the associated control signal (rd or wr ) is active. this also includes the programmable read/write delay. read chip select is only activated for read cycles, write chip select is only activated for write cycles, read/write chip select is activated for both read and write cycles (write cycles are assumed, if any of the signals wrh or wrl gets active). these modes save external glue logic, when accessing external devices like latches or drivers that only provide a single enable input. address chip select signals remain active during the complete bus cycle. for address chip select signals two generation modes can be selected via bit cscfg in register syscon: - a latched address chip select signal (cscfg= ? 0 ? ) becomes active with the falling edge of ale and becomes inactive at the beginning of an external bus cycle that accesses a different address window. no spikes will be generated on the chip select lines and no changes occur as long as locations within the same address window or within internal memory (excluding x-peripherals and xram) are accessed. - an early address chip select signal (cscfg= ? 1 ? ) becomes active together with the address and bhe (if enabled) and remains active until the end of the current bus cycle. early address chip select signals are not latched internally and may toggle intermediately while the address is changing. note: cs0 provides a latched address chip select directly after reset (except for single chip mode) when the first instruction is fetched. internal pullup devices hold all cs lines high during reset. after the end of a reset sequence the pullup devices are switched off and the pin drivers control the pin levels on the selected cs lines. not selected cs lines will enter the high-impedance state and are available for general purpose io. segment address versus chip select the external bus interface of the c161pi supports many configurations for the external memory. by increasing the number of segment address lines the c161pi can address a linear address space of 256 kbyte, 1 mbyte or 8 mbyte. this allows to implement a large sequential memory area, and also allows to access a great number of external devices, using an external decoder. by increasing the number of cs lines the c161pi can access memory banks or peripherals without external glue logic. these two features may be combined to optimize the overall system performance. note: bit sgtdis of register syscon defines, if the csp register is saved during interrupt entry (segmentation active) or not (segmentation disabled).
 ./0 1  user ? s manual 9-12 1999-08  9.3 programmable bus characteristics important timing characteristics of the external bus interface have been made user programmable to allow to adapt it to a wide range of different external bus and memory configurations with different types of memories and/or peripherals. the following parameters of an external bus cycle are programmable:  ale control defines the ale signal length and the address hold time after its falling edge  memory cycle time (extendable with 1...15 waitstates) defines the allowable access time  memory tri-state time (extendable with 1 waitstate) defines the time for a data driver to float  read/write delay time defines when a command is activated after the falling edge of ale  ready control defines, if a bus cycle is terminated internally or externally note: internal accesses are executed with maximum speed and therefore are not programmable. external accesses use the slowest possible bus cycle after reset. the bus cycle timing may then be optimized by the initialization software. figure 9-5 programmable external bus cycle alectl mctc mttc
 ./0 1  user ? s manual 9-13 1999-08  ale length control the length of the ale signal and the address hold time after its falling edge are controlled by the alectlx bits in the buscon registers. when bit alectl is set to ? 1 ? , external bus cycles accessing the respective address window will have their ale signal prolonged by half a cpu clock (1 tcl). also the address hold time after the falling edge of ale (on a multiplexed bus) will be prolonged by half a cpu clock, so the data transfer within a bus cycle refers to the same clkout edges as usual (i.e. the data transfer is delayed by one cpu clock). this allows more time for the address to be latched. note: alectl0 is ? 1 ? after reset to select the slowest possible bus cycle, the other alectlx are ? 0 ? after reset. figure 9-6 ale length control
 ./0 1  user ? s manual 9-14 1999-08  programmable memory cycle time the c161pi allows the user to adjust the controller ? s external bus cycles to the access time of the respective memory or peripheral. this access time is the total time required to move the data to the destination. it represents the period of time during which the controller ? s signals do not change. figure 9-7 memory cycle time the external bus cycles of the c161pi can be extended for a memory or peripheral, which cannot keep pace with the controller ? s maximum speed, by introducing wait states during the access (see figure above). during these memory cycle time wait states, the cpu is idle, if this access is required for the execution of the current instruction. the memory cycle time wait states can be programmed in increments of one cpu clock (2 tcl) within a range from 0 to 15 (default after reset) via the mctc fields of the buscon registers. 15- waitstates will be inserted.
 ./0 1  user ? s manual 9-15 1999-08  programmable memory tri-state time the c161pi allows the user to adjust the time between two subsequent external accesses to account for the tri-state time of the external device. the tri-state time defines, when the external device has released the bus after deactivation of the read command (rd ). figure 9-8 memory tri-state time the output of the next address on the external bus can be delayed for a memory or peripheral, which needs more time to switch off its bus drivers, by introducing a wait state after the previous bus cycle (see figure above). during this memory tri-state time wait state, the cpu is not idle, so cpu operations will only be slowed down if a subsequent external instruction or data fetch operation is required during the next instruction cycle. the memory tri-state time waitstate requires one cpu clock (2 tcl) and is controlled via the mttcx bits of the buscon registers. a waitstate will be inserted, if bit mttcx is ? 0 ? (default after reset). note: external bus cycles in multiplexed bus modes implicitly add one tri-state time waitstate in addition to the programmable mttc waitstate.
 ./0 1  user ? s manual 9-16 1999-08  read/write signal delay the c161pi allows the user to adjust the timing of the read and write commands to account for timing requirements of external peripherals. the read/write delay controls the time between the falling edge of ale and the falling edge of the command. without read/ write delay the falling edges of ale and command(s) are coincident (except for propagation delays). with the delay enabled, the command(s) become active half a cpu clock (1 tcl) after the falling edge of ale. the read/write delay does not extend the memory cycle time, and does not slow down the controller in general. in multiplexed bus modes, however, the data drivers of an external device may conflict with the c161pi ? s address, when the early rd signal is used. therefore multiplexed bus cycles should always be programmed with read/write delay. the read/write delay is controlled via the rwdcx bits in the buscon registers. the command(s) will be delayed, if bit rwdcx is ? 0 ? (default after reset). figure 9-9 read/write signal duration control 1) the data drivers from the previous bus cycle should be disabled when the rd signal becomes active.
 ./0 1  user ? s manual 9-17 1999-08  9.4 ready controlled bus cycles for situations, where the programmable waitstates are not enough, or where the response (access) time of a peripheral is not constant, the c161pi provides external bus cycles that are terminated via a ready input signal (synchronous or asynchronous). in this case the c161pi first inserts a programmable number of waitstates (0...7) and then monitors the ready line to determine the actual end of the current bus cycle. the external device drives ready low in order to indicate that data have been latched (write cycle) or are available (read cycle). figure 9-10 ready controlled bus cycles the ready function is enabled via the rdyenx bits in the buscon registers. when this function is selected (rdyenx = ? 1 ? ), only the lower 3 bits of the respective mctc bit field define the number of inserted waitstates (0...7), while the msb of bit field mctc selects the ready operation: mctc.3= ? 0 ? : synchronous ready , i.e. the ready signal must meet setup and hold times. mctc.3= ? 1 ? : asynchronous ready , i.e. the ready signal is synchronized internally.
 ./0 1  user ? s manual 9-18 1999-08  the synchronous ready provides the fastest bus cycles, but requires setup and hold times to be met. the clkout signal should be enabled and may be used by the peripheral logic to control the ready timing in this case. the asynchronous ready is less restrictive, but requires additional waitstates caused by the internal synchronization. as the asynchronous ready is sampled earlier (see figure above) programmed waitstates may be necessary to provide proper bus cycles (see also notes on ? normally-ready ? peripherals below). a ready signal (especially asynchronous ready ) that has been activated by an external device may be deactivated in response to the trailing (rising) edge of the respective command (rd or wr ). note: when the ready function is enabled for a specific address window, each bus cycle within this window must be terminated with an active ready signal. otherwise the controller hangs until the next reset. a timeout function is only provided by the watchdog timer. combining the ready function with predefined waitstates is advantageous in two cases: memory components with a fixed access time and peripherals operating with ready may be grouped into the same address window. the (external) waitstate control logic in this case would activate ready either upon the memory ? s chip select or with the peripheral ? s ready output. after the predefined number of waitstates the c161pi will check its ready line to determine the end of the bus cycle. for a memory access it will be low already (see example a) in the figure above), for a peripheral access it may be delayed (see example b) in the figure above). as memories tend to be faster than peripherals, there should be no impact on system performance. when using the ready function with so-called ? normally-ready ? peripherals, it may lead to erroneous bus cycles, if the ready line is sampled too early. these peripherals pull their ready output low, while they are idle. when they are accessed, they deactivate ready until the bus cycle is complete, then drive it low again. if, however, the peripheral deactivates ready after the first sample point of the c161pi, the controller samples an active ready and terminates the current bus cycle, which, of course, is too early. by inserting predefined waitstates the first ready sample point can be shifted to a time, where the peripheral has safely controlled the ready line (e.g. after 2 waitstates in the figure above).
 ./0 1  user ? s manual 9-19 1999-08  9.5 controlling the external bus controller a set of registers controls the functions of the ebc. general features like the usage of interface pins (wr , bhe ), segmentation and internal rom mapping are controlled via register syscon. the properties of a bus cycle like chip select mode, usage of ready , length of ale, external bus mode, read/write delay and waitstates are controlled via registers buscon4...buscon0. four of these registers (buscon4...buscon1) have an address select register (addrsel4...addrsel1) associated with them, which allows to specify up to four address areas and the individual bus characteristics within these areas. all accesses that are not covered by these four areas are then controlled via buscon0. this allows to use memory components or peripherals with different interfaces within the same system, while optimizing accesses to each of them. syscon system control register sfr (ff12 h /89 h ) reset value: 0xx0 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 stksz rom s1 sgt dis rom en byt dis clk en wr cfg cs cfg - owd dis bd rst en xpen visi- ble xper sha- re rw rw rw rwh rwh rw rwh rw - rwh rw rw rw rw bit function xper-share xbus peripheral share mode control 0: external accesses to xbus peripherals are disabled 1: xbus peripherals are accessible via the ext. bus during hold mode visible visible mode control 0: accesses to xbus peripherals are done internally 1: xbus peripheral accesses are made visible on the external pins xpen xbus peripheral enable bit 0: accesses to the on-chip x-peripherals and their functions are disabled 1: the on-chip x-peripherals are enabled and can be accessed bdrsten bidirectional reset enable bit 0: pin rstin is an input only. 1: pin rstin is pulled low during the internal reset sequence after any reset. owddis oscillator watchdog disable bit 0: the on-chip oscillator watchdog is enabled and active. 1: the on-chip oscillator watchdog is disabled and the cpu clock is always fed from the oscillator input.
 ./0 1  user ? s manual 9-20 1999-08  note: register syscon cannot be changed after execution of the einit instruction. bit sgtdis controls the correct stack operation (push/pop of csp or not) during traps and interrupts. the layout of the buscon registers and addrsel registers is identical. registers buscon4...buscon1, which control the selected address windows, are completely under software control, while register buscon0, which e.g. is also used for the very first code access after reset, is partly controlled by hardware, i.e. it is initialized via port0 during the reset sequence. this hardware control allows to define an appropriate external bus for systems, where no internal program memory is provided. cscfg chip select configuration control 0: latched cs mode. the cs signals are latched internally and driven to the (enabled) port pins synchronously. 1: unlatched cs mode. the cs signals are directly derived from the address and driven to the (enabled) port pins. wrcfg write configuration control (set according to pin p0h.0 during reset) 0: pins wr and bhe retain their normal function 1: pin wr acts as wrl , pin bhe acts as wrh clken system clock output enable (clkout) 0: clkout disabled: pin may be used for general purpose io or for signal fout 1: clkout enabled: pin outputs the system clock signal bytdis disable/enable control for pin bhe (set according to data bus width) 0: pin bhe enabled 1: pin bhe disabled, pin may be used for general purpose io romen internal rom enable (set according to pin ea during reset) 0: internal program memory disabled, accesses to the rom area use the external bus 1: internal program memory enabled sgtdis segmentation disable/enable control 0: segmentation enabled (csp is saved/restored during interrupt entry/exit) 1: segmentation disabled (only ip is saved/restored) roms1 internal rom mapping 0: internal rom area mapped to segment 0 (00 ? 0000 h ...00 ? 7fff h ) 1: internal rom area mapped to segment 1 (01 ? 0000 h ...01 ? 7fff h ) stksz system stack size selects the size of the system stack (in the internal ram) from 32 to 512 words bit function
 ./0 1  user ? s manual 9-21 1999-08  note: buscon0 is initialized with 0000 h , if pin ea is high during reset. if pin ea is low during reset, bits busact0 and alectl0 are set ( ? 1 ? ) and bit field btyp is loaded buscon0 bus control register 0 sfr (ff0c h /86 h ) reset value: 0xx0 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 csw en0 csr en0 - rdy en0 - bus act 0 ale ctl 0 -btyp mtt c0 rwd c0 mctc rw rw - rw - rwh rwh - rwh rw rw rw buscon1 bus control register 1 sfr (ff14 h /8a h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 csw en1 csr en1 - rdy en1 - bus act 1 ale ctl 1 -btyp mtt c1 rwd c1 mctc rw rw - rw - rw rw - rw rw rw rw buscon2 bus control register 2 sfr (ff16 h /8b h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 csw en2 csr en2 - rdy en2 - bus act 2 ale ctl 2 -btyp mtt c2 rwd c2 mctc rw rw - rw - rw rw - rw rw rw rw buscon3 bus control register 3 sfr (ff18 h /8c h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 csw en3 csr en3 - rdy en3 - bus act 3 ale ctl 3 -btyp mtt c3 rwd c3 mctc rw rw - rw - rw rw - rw rw rw rw buscon4 bus control register 4 sfr (ff1a h /8d h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 csw en4 csr en4 - rdy en4 - bus act 4 ale ctl 4 -btyp mtt c4 rwd c4 mctc rw rw - rw - rw rw - rw rw rw rw
 ./0 1  user ? s manual 9-22 1999-08  with the bus configuration selected via port0. bit function mctc memory cycle time control (number of memory cycle time wait states) 0000: 15 waitstates . . . (number = 15 - ) 1111: no waitstates note: the definition of bitfield mctcx changes if rdyenx = ? 1 ? (see page 17) rwdcx read/write delay control for busconx 0: with rd/wr delay: activate command 1 tcl after falling edge of ale 1: no rd/wr delay: activate command with falling edge of ale mttcx memory tristate time control 0: 1 waitstate 1: no waitstate btyp external bus configuration 00: 8-bit demultiplexed bus 01: 8-bit multiplexed bus 10: 16-bit demultiplexed bus 11: 16-bit multiplexed bus note: for buscon0 btyp is defined via port0 during reset. alectlx ale lengthening control 0: normal ale signal 1: lengthened ale signal busactx bus active control 0: external bus disabled 1: external bus enabled within respective address window (addrsel) rdyenx ready input enable 0: external bus cycle is controlled by bit field mctc only 1: external bus cycle is controlled by the ready input signal csrenx read chip select enable 0: the cs signal is independent of the read command (rd ) 1: the cs signal is generated for the duration of the read command cswenx write chip select enable 0: the cs signal is independent of the write cmd. (wr ,wrl ,wrh ) 1: the cs signal is generated for the duration of the write command
 ./0 1  user ? s manual 9-23 1999-08  note: there is no register addrsel0, as register buscon0 controls all external accesses outside the four address windows of buscon4...buscon1 within the complete address space. addrsel1 address select register 1 sfr (ff18 h /0c h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 rgsad rgsz rw rw addrsel2 address select register 2 sfr (fe1a h /0d h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 rgsad rgsz rw rw addrsel3 address select register 3 sfr (fe1c h /0e h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 rgsad rgsz rw rw addrsel4 address select register 4 sfr (fe1e h /0f h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 rgsad rgsz rw rw bit function rgsz range size selection defines the size of the address area controlled by the respective busconx/addrselx register pair. see table below. rgsad range start address defines the upper bits of the start address of the respective address area. see table below.
 ./0 1  user ? s manual 9-24 1999-08  definition of address areas the four register pairs buscon4/addrsel4...buscon1/addrsel1 allow to define 4 separate address areas within the address space of the c161pi. within each of these address areas external accesses can be controlled by one of the four different bus modes, independent of each other and of the bus mode specified in register buscon0. each addrselx register in a way cuts out an address window, within which the parameters in register busconx are used to control external accesses. the range start address of such a window defines the upper address bits, which are not used within the address window of the specified size (see table below). for a given window size only those upper address bits of the start address are used (marked ? r ? ), which are not implicitly used for addresses inside the window. the lower bits of the start address (marked ? x ? ) are disregarded. table 9-6 address window definition bit field rgsz resulting window size relevant bits (r) of start addr. ( a12... ) 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 x x 4 kbyte 8 kbyte 16 kbyte 32 kbyte 64 kbyte 128 kbyte 256 kbyte 512 kbyte 1 mbyte 2 mbyte 4 mbyte 8 mbyte reserved. rrrrrrrrrrrr rrrrrrrrrrrx rrrrrrrrrrx x rrrrrrrrrx x x rrrrrrrrx x x x rrrrrrrx x x x x rrrrrr xxxxxx rrrrr xxxxxxx rrrr xxxxxxxx rrrxxxxxxxxx rrxxxxxxxxxx rxxxxxxxxxxx
 ./0 1  user ? s manual 9-25 1999-08  address window arbitration the address windows that can be defined within the c161pi ? s address space may partly overlap each other. thus e.g. small areas may be cut out of bigger windows in order to effectively utilize external resources, especially within segment 0. for each access the ebc compares the current address with all address select registers (programmable addrselx and hardwired xadrsx). this comparison is done in four levels. priority 1 :the hardwired xadrsx registers are evaluated first. a match with one of these registers directs the access to the respective x-peripheral using the corresponding xbconx register and ignoring all other addrselx registers. priority 2 :registers addrsel2 and addrsel4 are evaluated before addrsel1 and addrsel3, respectively. a match with one of these registers directs the access to the respective external area using the corresponding bus- conx register and ignoring registers addrsel1/3 (see figure below). priority 3 :a match with registers addrsel1 or addrsel3 directs the access to the respective external area using the corresponding busconx register. priority 4 :if there is no match with any xadrsx or addrselx register the access to the external bus uses register buscon0. figure 9-11 address window arbitration note: only the indicated overlaps are defined. all other overlaps lead to erroneous bus cycles. e.g. addrsel4 may not overlap addrsel2 or addrsel1. the hardwired xadrsx registers are defined non-overlapping. active window inactive window buscon0 buscon1 buscon2 xbcon0 buscon3 buscon4
 ./0 1  user ? s manual 9-26 1999-08  note: rp0h cannot be changed via software, but rather allows to check the current configuration. precautions and hints  the ext. bus interface is enabled as long as at least one of the buscon registers has its busact bit set.  port1 will output the intra-segment addr. as long as at least one of the buscon registers selects a demultiplexed external bus, even for multiplexed bus cycles.  not all addr. windows defined via registers addrselx may overlap each other. the operation of the ebc will be unpredictable in such a case. see chapter ? address window arbitration ? .  the addr. windows defined via registers addrselx may overlap internal addr. areas. internal accesses will be executed in this case.  for any access to an internal addr. area the ebc will remain inactive (see ebc idle state). rp0h reset value of p0h sfr (f108 h /84 h ) reset value: - - xx h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 clkcfg salsel cssel wrc rh rh rh rh bit function wrc write configuration 0: pins wr and bhe operate as wrl and wrh signals 1: pins wr and bhe operate as wr and bhe signals cssel chip select line selection (number of active cs outputs) 00: 3 cs lines: cs2 ...cs0 01: 2 cs lines: cs1 ...cs0 10: no cs lines at all 11: 5 cs lines: cs4 ...cs0 (default without pulldowns) salsel segment address line selection (nr. of active segment addr. outputs) 00: 4-bit segment address: a19...a16 01: no segment address lines at all 10: 7-bit segment address: a22...a16 11: 2-bit segment address: a17...a16 (default without pulldowns) clkcfg clock generation mode configuration these pins define the clock generation mode, i.e. the mechanism how the internal cpu clock is generated from the externally applied (xtal1) input clock.
 ./0 1  user ? s manual 9-27 1999-08  9.6 ebc idle state when the external bus interface is enabled, but no external access is currently executed, the ebc is idle. as long as only internal resources (from an architecture point of view) like iram, gprs or sfrs, etc. are used the external bus interface does not change (see table below). accesses to on-chip x-peripherals are also controlled by the ebc. however, even though an x-peripheral appears like an external peripheral to the controller, the respective accesses do not generate valid external bus cycles. due to timing constraints address and write data of an xbus cycle are reflected on the external bus interface (see table below). the ? address ? mentioned above includes port1, port 4, bhe and ale which also pulses for an xbus cycle. the external cs signals on port 6 are driven inactive (high) because the ebc switches to an internal xcs signal. the external control signals (rd and wr or wrl /wrh if enabled) remain inactive (high). table 9-7 status of the external bus interface during ebc idle state pins internal accesses only xbus accesses port0 tristated (floating) tristated (floating) for read accesses xbus write data for write accesses port1 last used external address (if used for the bus interface) last used xbus address (if used for the bus interface) port 4 last used external segment address (on selected pins) last used xbus segment address (on selected pins) port 6 active external cs signal corresponding to last used address inactive (high) for selected cs signals bhe level corresponding to last external access level corresponding to last xbus access ale inactive (low) pulses as defined for x-peripheral rd inactive (high) inactive (high) wr /wrl inactive (high) inactive (high) wrh inactive (high) inactive (high)
 ./0 1  user ? s manual 9-28 1999-08  9.7 the xbus interface the c161pi provides an on-chip interface (the xbus interface), via which integrated customer/application specific peripherals can be connected to the standard controller core. the xbus is an internal representation of the external bus interface, i.e. it is operated in the same way. for each peripheral on the xbus (x-peripheral) there is a separate address window controlled by a register pair xbconx/xadrsx (similar to registers busconx and addrselx). as an interface to a peripheral in many cases is represented by just a few registers, the registers partly select smaller address windows than the standard addrsel registers. as the register pairs control integrated peripherals rather than externally connected ones, most of them are fixed by mask programming rather than being user programmable. x-peripheral accesses provide the same choices as external accesses, so these peripherals may be bytewide or wordwide. because the on-chip connection can be realized very efficient and for performance reasons x-peripherals are only implemented with a separate address bus, i.e. in demultiplexed bus mode. interrupt nodes are provided for x-peripherals to be integrated. note: if you plan to develop a peripheral of your own to be integrated into a c161pi device to create a customer specific version, please ask for the specification of the xbus interface and for further support. enabling of xbus peripherals after reset all on-chip xbus peripherals are disabled. in order to be usable an xbus peripheral must be enabled via the global enable bit xpen in register syscon. the following table summarizes the xbus peripherals and also the number of waitstates which are used when accessing the respective peripheral. table 9-8 xbus peripherals in the c161pi associated xbus peripheral waitstates i 2 c0 xram 2 kbyte 0
 & !    user ? s manual 10-1 1999-08  10 the general purpose timer units the general purpose timer units gpt1 and gpt2 represent very flexible multifunctional timer structures which may be used for timing, event counting, pulse width measurement, pulse generation, frequency multiplication, and other purposes. they incorporate five 16-bit timers that are grouped into the two timer blocks gpt1 and gpt2. block gpt1 contains 3 timers/counters with a maximum resolution of 16 tcl, while block gpt2 contains 2 timers/counters with a maximum resolution of 8 tcl and a 16-bit capture/reload register (caprel). each timer in each block may operate independently in a number of different modes such as gated timer or counter mode, or may be concatenated with another timer of the same block. the auxiliary timers of gpt1 may optionally be configured as reload or capture registers for the core timer. in the gpt2 block, the additional caprel register supports capture and reload operation with extended functionality. each block has alternate input/output functions and specific interrupts associated with it. 10.1 timer block gpt1 from a programmer ? s point of view, the gpt1 block is composed of a set of sfrs as summarized below. those portions of port and direction registers which are used for alternate functions by the gpt1 block are shaded. figure 10-1 sfrs and port pins associated with timer block gpt1 t3 t2 p5 t4ic t2 gpt1 timer 2 register t3 gpt1 timer 3 register t4 gpt1 timer 4 register t2ic gpt1 timer 2 interrupt control register t3ic gpt1 timer 3 interrupt control register t4ic gpt1 timer 4 interrupt control register t2in/p3.7 t2eud/p5.15 t3in/p3.6 t3eud/p3.4 t4in/p3.5 t4eud/p5.14 t3out/p3.3 t2con ports & direction control alternate functions data registers control registers interrupt control t2ic dp3 p3 t4 t3ic t3con t4con odp3 port 3 open drain control register dp3 port 3 direction control register p3 port 3 data register t2con gpt1 timer 2 control register t3con gpt1 timer 3 control register t4con gpt1 timer 4 control register odp3
 & !    user ? s manual 10-2 1999-08  all three timers of block gpt1 (t2, t3, t4) can run in 4 basic modes, which are timer, gated timer, counter and incremental interface mode, and all timers can either count up or down. each timer has an alternate input function pin (txin) associated with it which serves as the gate control in gated timer mode, or as the count input in counter mode. the count direction (up / down) may be programmed via software or may be dynamically altered by a signal at an external control input pin. each overflow/underflow of core timer t3 is latched in the toggle flipflop t3otl and may be indicated on an alternate output function pin. the auxiliary timers t2 and t4 may additionally be concatenated with the core timer, or used as capture or reload registers for the core timer. the current contents of each timer can be read or modified by the cpu by accessing the corresponding timer registers t2, t3, or t4, which are located in the non-bitaddressable sfr space. when any of the timer registers is written to by the cpu in the state immediately before a timer increment, decrement, reload, or capture is to be performed, the cpu write operation has priority in order to guarantee correct results. figure 10-2 gpt1 block diagram t3 mode control 2 n : 1 f cpu 2 n : 1 f cpu t2 mode control gpt1 timer t2 reload capture 2 n : 1 f cpu t4 mode control gpt1 timer t4 reload capture gpt1 timer t3 t3otl u/d t2eud t2in t3in t3eud t4in t4eud t3out toggle ff u/d u/d interrupt request interrupt request interrupt request other timers mct02141
 & !    user ? s manual 10-3 1999-08  10.1.1 gpt1 core timer t3 the core timer t3 is configured and controlled via its bitaddressable control register t3con. *) for the effects of bits t3ud and t3ude refer to the direction table below. t3con timer 3 control register sfr (ff42 h /a1 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ----- t3 otl t3 oe t3 ude t3 ud t3r t3m t3i - - - - - rwh rw rw rw rw rw rw bit function t3i timer 3 input selection depends on the operating mode, see respective sections. t3m timer 3 mode control (basic operating mode) 000: timer mode 001: counter mode 010: gated timer with gate active low 011: gated timer with gate active high 100: reserved . do not use this combination. 101: reserved . do not use this combination. 110: incremental interface mode 111: reserved . do not use this combination. t3r timer 3 run bit 0: timer / counter 3 stops 1: timer / counter 3 runs t3ud timer 3 up / down control *) t3ude timer 3 external up/down enable *) t3oe alternate output function enable 0: alternate output function disabled 1: alternate output function enabled t3otl timer 3 output toggle latch toggles on each overflow / underflow of t3. can be set or reset by software.
 & !    user ? s manual 10-4 1999-08  timer 3 run bit the timer can be started or stopped by software through bit t3r (timer t3 run bit). if t3r= ? 0 ? , the timer stops. setting t3r to ? 1 ? will start the timer. in gated timer mode, the timer will only run if t3r= ? 1 ? and the gate is active (high or low, as programmed). count direction control the count direction of the core timer can be controlled either by software or by the external input pin t3eud (timer t3 external up/down control input), which is an alternate port input function. these options are selected by bits t3ud and t3ude in control register t3con. when the up/down control is done by software (bit t3ude= ? 0 ? ), the count direction can be altered by setting or clearing bit t3ud. when t3ude= ? 1 ? , pin t3eud is selected to be the controlling source of the count direction. however, bit t3ud can still be used to reverse the actual count direction, as shown in the table below. if t3ud= ? 0 ? and pin t3eud shows a low level, the timer is counting up. with a high level at t3eud the timer is counting down. if t3ud= ? 1 ? , a high level at pin t3eud specifies counting up, and a low level specifies counting down. the count direction can be changed regardless of whether the timer is running or not. when pin t3eud is used as external count direction control input, it must be configured as input, i.e. its corresponding direction control bit must be set to ? 0 ? . note: the direction control works the same for core timer t3 and for auxiliary timers t2 and t4. therefore the pins and bits are named tx... table 10-1 gpt1 core timer t3 count direction control pin txeud bit txude bit txud count direction x 0 0 count up x 0 1 count down 0 1 0 count up 1 1 0 count down 0 1 1 count down 1 1 1 count up
 & !    user ? s manual 10-5 1999-08  timer 3 output toggle latch an overflow or underflow of timer t3 will clock the toggle bit t3otl in control register t3con. t3otl can also be set or reset by software. bit t3oe (alternate output function enable) in register t3con enables the state of t3otl to be an alternate function of the external output pin t3out. for that purpose, a ? 1 ? must be written into the respective port data latch and pin t3out must be configured as output by setting the corresponding direction control bit to ? 1 ? . if t3oe= ? 1 ? , pin t3out then outputs the state of t3otl. if t3oe= ? 0 ? , pin t3out can be used as general purpose io pin. in addition, t3otl can be used in conjunction with the timer over/underflows as an input for the counter function or as a trigger source for the reload function of the auxiliary timers t2 and t4. for this purpose, the state of t3otl does not have to be available at pin t3out, because an internal connection is provided for this option. timer 3 in timer mode timer mode for the core timer t3 is selected by setting bit field t3m in register t3con to ? 000 b ? . in this mode, t3 is clocked with the internal system clock (cpu clock) divided by a programmable prescaler, which is selected by bit field t3i. the input frequency f t3 for timer t3 and its resolution r t3 are scaled linearly with lower clock frequencies f cpu , as can be seen from the following formula: figure 10-3 block diagram of core timer t3 in timer mode f t3 = f cpu 8 * 2 r t3 [ s] = f cpu [mhz] 8 * 2 core timer tx txotl interrupt request txoe txout txr 2 n : 1 txl exor 0 mux 1 up/ down txeud txude mcb02028 txud f cpu t3eud = p3.4 t3out = p3.3 x = 3
 & !    user ? s manual 10-6 1999-08  the timer input frequencies, resolution and periods which result from the selected prescaler option are listed in the table below. this table also applies to the gated timer mode of t3 and to the auxiliary timers t2 and t4 in timer and gated timer mode. note that some numbers may be rounded to 3 significant digits. table 10-2 gpt1 timer input frequencies, resolution and periods f cpu = 20mhz timer input selection t2i / t3i / t4i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 8 16 32 64 128 256 512 1024 input frequency 2.5 mhz 1.25 mhz 625 khz 312.5 khz 156.25 khz 78.125 khz 39.06 khz 19.53 khz resolution 400 ns 800 ns 1.6 s 3.2 s 6.4 s 12.8 s 25.6 s 51.2 s period 26 ms 52.5 ms 105 ms 210 ms 420 ms 840 ms 1.68 s 3.36 s
 & !    user ? s manual 10-7 1999-08  timer 3 in gated timer mode gated timer mode for the core timer t3 is selected by setting bit field t3m in register t3con to ? 010 b ? or ? 011 b ? . bit t3m.0 (t3con.3) selects the active level of the gate input. in gated timer mode the same options for the input frequency as for the timer mode are available. however, the input clock to the timer in this mode is gated by the external input pin t3in (timer t3 external input). to enable this operation pin t3in must be configured as input, i.e. the corresponding direction control bit must contain ? 0 ? . figure 10-4 block diagram of core timer t3 in gated timer mode if t3m.0= ? 0 ? , the timer is enabled when t3in shows a low level. a high level at this pin stops the timer. if t3m.0= ? 1 ? , pin t3in must have a high level in order to enable the timer. in addition, the timer can be turned on or off by software using bit t3r. the timer will only run, if t3r= ? 1 ? and the gate is active. it will stop, if either t3r= ? 0 ? or the gate is inactive. note: a transition of the gate signal at pin t3in does not cause an interrupt request. core timer tx txotl interrupt request txoe txout txr mux xor 0 mux 1 up/ down txeud txude mcb02029 txud 2 n : 1 txi f cpu txm txin t3in = p3.6 t3eud = p3.4 t3out = p3.3 x = 3
 & !    user ? s manual 10-8 1999-08  timer 3 in counter mode counter mode for the core timer t3 is selected by setting bit field t3m in register t3con to ? 001 b ? . in counter mode timer t3 is clocked by a transition at the external input pin t3in. the event causing an increment or decrement of the timer can be a positive, a negative, or both a positive and a negative transition at this pin. bit field t3i in control register t3con selects the triggering transition (see table below). figure 10-5 block diagram of core timer t3 in counter mode table 10-3 gpt1 core timer t3 (counter mode) input edge selection t3i triggering edge for counter increment / decrement 0 0 0 none. counter t3 is disabled 0 0 1 positive transition (rising edge) on t3in 0 1 0 negative transition (falling edge) on t3in 0 1 1 any transition (rising or falling edge) on t3in 1 x x reserved. do not use this combination core timer tx txr xor 0 mux 1 up/ down txeud txude mcb02030 txud txl txin edge select txotl interrupt request txoe txout t3in = p3.6 t3eud = p3.4 t3out = p3.3 x = 3
 & !    user ? s manual 10-9 1999-08  for counter operation, pin t3in must be configured as input, i.e. the respective direction control bit dpx.y must be ? 0 ? . the maximum input frequency which is allowed in counter mode is f cpu /16. to ensure that a transition of the count input signal which is applied to t3in is correctly recognized, its level should be held high or low for at least 8 f cpu cycles before it changes. timer 3 in incremental interface mode incremental interface mode for the core timer t3 is selected by setting bit field t3m in register t3con to ? 110 b ? . in incremental interface mode the two inputs associated with timer t3 (t3in, t3eud) are used to interface to an incremental encoder. t3 is clocked by each transition on one or both of the external input pins which gives 2-fold or 4-fold resolution of the encoder input. figure 10-6 block diagram of core timer t3 in incremental interface mode bitfield t3i in control register t3con selects the triggering transitions (see table below). in this mode the sequence of the transitions of the two input signals is evaluated and generates count pulses as well as the direction signal. so t3 is modified automatically according to the speed and the direction of the incremental encoder and its contents therefore always represent the encoder ? s current position. edge select timer t3 xor 0 mux 1 t3eud t3ude mcb04000b t3ud t3l t3in t3otl interrupt request t3out phase detect t3oe t3r
 & !    user ? s manual 10-10 1999-08  the incremental encoder can be connected directly to the c161pi without external interface logic. in a standard system, however, comparators will be employed to convert the encoder ? s differential outputs (e.g. a, a ) to digital signals (e.g. a). this greatly increases noise immunity. note: the third encoder output top0, which indicates the mechanical zero position, may be connected to an external interrupt input and trigger a reset of timer t3 ( e.g. via pec transfer from zeros). figure 10-7 connection of the encoder to the c161pi for incremental interface operation the following conditions must be met:  bitfield t3m must be ? 110 b ? .  both pins t3in and t3eud must be configured as input, i.e. the respective direction control bits must be ? 0 ? .  bit t3ude must be ? 1 ? to enable automatic direction control. table 10-4 gpt1 core timer t3 (incremental interface mode) input edge selection t3i triggering edge for counter increment / decrement 0 0 0 none. counter t3 stops. 0 0 1 any transition (rising or falling edge) on t3in. 0 1 0 any transition (rising or falling edge) on t3eud. 0 1 1 any transition (rising or falling edge) on any t3 input (t3in or t3eud). 1 x x reserved. do not use this combination a c161pi a b b t0 t0 a b t0 encoder signal conditioning t3input t3input interrupt
 & !    user ? s manual 10-11 1999-08  the maximum input frequency which is allowed in incremental interface mode is f cpu /16. to ensure that a transition of any input signal is correctly recognized, its level should be held high or low for at least 8 f cpu cycles before it changes. in incremental interface mode the count direction is automatically derived from the sequence in which the input signals change, which corresponds to the rotation direction of the connected sensor. the table below summarizes the possible combinations. the figures below give examples of t3 ? s operation, visualizing count signal generation and direction control. it also shows how input jitter is compensated which might occur if the sensor rests near to one of its switching points. figure 10-8 evaluation of the incremental encoder signals table 10-5 gpt1 core timer t3 (incremental interface mode) count direction level on respective other input t3in input t3eud input rising falling rising falling high down up up down low up down down up t3in t3eud contents of t3 forward forward backward jitter jitter u p d own u p note: this example shows the timer behaviour assuming that t3 counts upon any transition on any input, i.e. t3i = ? 011 b ? .
 & !    user ? s manual 10-12 1999-08  figure 10-9 evaluation of the incremental encoder signals note: timer t3 operating in incremental interface mode automatically provides information on the sensor ? s current position. dynamic information (speed, acceleration, deceleration) may be obtained by measuring the incoming signal periods. this is facilitated by an additional special capture mode for timer t5. t3in t3eud contents of t3 forward forward backward jitter jitter u p down up note: this example shows the timer behaviour assuming that t3 counts upon any transition on input t3in, i.e. t3i = ? 001 b ? .
 & !    user ? s manual 10-13 1999-08  10.1.2 gpt1 auxiliary timers t2 and t4 both auxiliary timers t2 and t4 have exactly the same functionality. they can be configured for timer, gated timer, counter, or incremental interface mode with the same options for the timer frequencies and the count signal as the core timer t3. in addition to these 4 counting modes, the auxiliary timers can be concatenated with the core timer, or they may be used as reload or capture registers in conjunction with the core timer. the individual configuration for timers t2 and t4 is determined by their bitaddressable control registers t2con and t4con, which are both organized identically. note that functions which are present in all 3 timers of block gpt1 are controlled in the same bit positions and in the same manner in each of the specific control registers. t2con timer 2 control register sfr (ff40 h /a0 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------- t2 ude t2 ud t2r t2m t2i - - - - - - - rw rw rw rw rw t4con timer 4 control register sfr (ff44 h /a2 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------- t4 ude t4 ud t4r t4m t4i - - - - - - - rw rw rw rw rw bit function txi timer x input selection depends on the operating mode, see respective sections. txm timer x mode control (basic operating mode) 000: timer mode 001: counter mode 010: gated timer with gate active low 011: gated timer with gate active high 100: reload mode 101: capture mode 110: incremental interface mode 111: reserved . do not use this combination. txr timer x run bit 0: timer / counter x stops 1: timer / counter x runs
 & !    user ? s manual 10-14 1999-08  *) for the effects of bits txud and txude refer to the direction table (see t3 section). note: the auxiliary timers have no output toggle latch and no alternate output function. count direction control for auxiliary timers the count direction of the auxiliary timers can be controlled in the same way as for the core timer t3. the description and the table apply accordingly. timers t2 and t4 in timer mode or gated timer mode when the auxiliary timers t2 and t4 are programmed to timer mode or gated timer mode, their operation is the same as described for the core timer t3. the descriptions, figures and tables apply accordingly with one exception:  there is no output toggle latch for t2 and t4. timers t2 and t4 in incremental interface mode when the auxiliary timers t2 and t4 are programmed to incremental interface mode, their operation is the same as described for the core timer t3. the descriptions, figures and tables apply accordingly. txud timer x up / down control *) txude timer x external up/down enable *) bit function
 & !    user ? s manual 10-15 1999-08  timers t2 and t4 in counter mode counter mode for the auxiliary timers t2 and t4 is selected by setting bit field txm in the respective register txcon to ? 001 b ? . in counter mode timers t2 and t4 can be clocked either by a transition at the respective external input pin txin, or by a transition of timer t3 ? s output toggle latch t3otl. figure 10-10 block diagram of an auxiliary timer in counter mode the event causing an increment or decrement of a timer can be a positive, a negative, or both a positive and a negative transition at either the respective input pin, or at the toggle latch t3otl. bit field txi in the respective control register txcon selects the triggering transition (see table below). auxiliary timer tx interrupt request txr xor 0 mux 1 up/ down txeud txude mcb02221 txud txl txin edge select x = 2,4
 & !    user ? s manual 10-16 1999-08  note: only state transitions of t3otl which are caused by the overflows/underflows of t3 will trigger the counter function of t2/t4. modifications of t3otl via software will not trigger the counter function of t2/t4. for counter operation, pin txin must be configured as input, i.e. the respective direction control bit must be ? 0 ? . the maximum input frequency which is allowed in counter mode is f cpu /16. to ensure that a transition of the count input signal which is applied to txin is correctly recognized, its level should be held for at least 8 f cpu cycles before it changes. table 10-6 gpt1 auxiliary timer (counter mode) input edge selection t2i / t4i triggering edge for counter increment / decrement x 0 0 none. counter tx is disabled 0 0 1 positive transition (rising edge) on txin 0 1 0 negative transition (falling edge) on txin 0 1 1 any transition (rising or falling edge) on txin 1 0 1 positive transition (rising edge) of output toggle latch t3otl 1 1 0 negative transition (falling edge) of output toggle latch t3otl 1 1 1 any transition (rising or falling edge) of output toggle latch t3otl
 & !    user ? s manual 10-17 1999-08  timer concatenation using the toggle bit t3otl as a clock source for an auxiliary timer in counter mode concatenates the core timer t3 with the respective auxiliary timer. depending on which transition of t3otl is selected to clock the auxiliary timer, this concatenation forms a 32- bit or a 33-bit timer/counter.  32-bit timer/counter : if both a positive and a negative transition of t3otl is used to clock the auxiliary timer, this timer is clocked on every overflow/underflow of the core timer t3. thus, the two timers form a 32-bit timer.  33-bit timer/counter : if either a positive or a negative transition of t3otl is selected to clock the auxiliary timer, this timer is clocked on every second overflow/underflow of the core timer t3. this configuration forms a 33-bit timer (16-bit core timer+t3otl+16- bit auxiliary timer). the count directions of the two concatenated timers are not required to be the same. this offers a wide variety of different configurations. t3 can operate in timer, gated timer or counter mode in this case. figure 10-11 concatenation of core timer t3 and an auxiliary timer *) note: line only affected by over/underflows of t3, but not by software modifications of t3otl. t3out= p3.3 x = 2,4 y = 3 core timer ty tyotl interrupt request tyoe tyout tyr 2 n : 1 mcb02034 f cpu up/down auxiliary timer tx txr txl edge select txir interrupt request *) up/down
 & !    user ? s manual 10-18 1999-08  auxiliary timer in reload mode reload mode for the auxiliary timers t2 and t4 is selected by setting bit field txm in the respective register txcon to ? 100 b ? . in reload mode the core timer t3 is reloaded with the contents of an auxiliary timer register, triggered by one of two different signals. the trigger signal is selected the same way as the clock source for counter mode (see table above), i.e. a transition of the auxiliary timer ? s input or the output toggle latch t3otl may trigger the reload. note: when programmed for reload mode, the respective auxiliary timer (t2 or t4) stops independent of its run flag t2r or t4r. figure 10-12 gpt1 auxiliary timer in reload mode upon a trigger signal t3 is loaded with the contents of the respective timer register (t2 or t4) and the interrupt request flag (t2ir or t4ir) is set. note: when a t3otl transition is selected for the trigger signal, also the interrupt request flag t3ir will be set upon a trigger, indicating t3 ? s overflow or underflow. modifications of t3otl via software will not trigger the counter function of t2/t4. reload register tx core timer t3 up/down source/edge select t3otl interrupt request t3oe t3out txin input clock txi *) interrupt request mcb02035 *) note: line only affected by over/underflows of t3, but not by software modifications of t3otl. x=2,4
 & !    user ? s manual 10-19 1999-08  the reload mode triggered by t3otl can be used in a number of different configurations. depending on the selected active transition the following functions can be performed:  if both a positive and a negative transition of t3otl is selected to trigger a reload, the core timer will be reloaded with the contents of the auxiliary timer each time it overflows or underflows. this is the standard reload mode (reload on overflow/ underflow).  if either a positive or a negative transition of t3otl is selected to trigger a reload, the core timer will be reloaded with the contents of the auxiliary timer on every second overflow or underflow.  using this ? single-transition ? mode for both auxiliary timers allows to perform very flexible pulse width modulation (pwm). one of the auxiliary timers is programmed to reload the core timer on a positive transition of t3otl, the other is programmed for a reload on a negative transition of t3otl. with this combination the core timer is alternately reloaded from the two auxiliary timers. the figure below shows an example for the generation of a pwm signal using the alternate reload mechanism. t2 defines the high time of the pwm signal (reloaded on positive transitions) and t4 defines the low time of the pwm signal (reloaded on negative transitions). the pwm signal can be output on t3out with t3oe = ? 1 ? , port latch = ? 1 ? and direction bit = ? 1 ? . with this method the high and low time of the pwm signal can be varied in a wide range. note: the output toggle latch t3otl is accessible via software and may be changed, if required, to modify the pwm signal. however, this will not trigger the reloading of t3.
 & !    user ? s manual 10-20 1999-08  figure 10-13 gpt1 timer reload configuration for pwm generation note: although it is possible, it should be avoided to select the same reload trigger event for both auxiliary timers. in this case both reload registers would try to load the core timer at the same time. if this combination is selected, t2 is disregarded and the contents of t4 is reloaded. *) note: lines only affected by over/underflows of t3, but not by software modifications of t3otl. core timer t3 up/down t3otl interrupt request t3oe t3out interrupt request reload register t2 interrupt request reload register t4 t2i *) *) t4i input clock mcb02037
 & !    user ? s manual 10-21 1999-08  auxiliary timer in capture mode capture mode for the auxiliary timers t2 and t4 is selected by setting bit field txm in the respective register txcon to ? 101 b ? . in capture mode the contents of the core timer are latched into an auxiliary timer register in response to a signal transition at the respective auxiliary timer's external input pin txin. the capture trigger signal can be a positive, a negative, or both a positive and a negative transition. the two least significant bits of bit field txi are used to select the active transition (see table in the counter mode section), while the most significant bit txi.2 is irrelevant for capture mode. it is recommended to keep this bit cleared (txi.2 = ? 0 ? ). note: when programmed for capture mode, the respective auxiliary timer (t2 or t4) stops independent of its run flag t2r or t4r. figure 10-14 gpt1 auxiliary timer in capture mode upon a trigger (selected transition) at the corresponding input pin txin the contents of the core timer are loaded into the auxiliary timer register and the associated interrupt request flag txir will be set. note: the direction control bits for t2in and t4in must be set to ? 0 ? , and the level of the capture trigger signal should be held high or low for at least 8 f cpu cycles before it changes to ensure correct edge detection. capture register tx core timer t3 up/down edge select t3otl interrupt request t3oe t3out txin input clock interrupt request mcb02038 txi x=2,4
 & !    user ? s manual 10-22 1999-08  10.1.3 interrupt control for gpt1 timers when a timer overflows from ffff h to 0000 h (when counting up), or when it underflows from 0000 h to ffff h (when counting down), its interrupt request flag (t2ir, t3ir or t4ir) in register txic will be set. this will cause an interrupt to the respective timer interrupt vector (t2int, t3int or t4int) or trigger a pec service, if the respective interrupt enable bit (t2ie, t3ie or t4ie in register txic) is set. there is an interrupt control register for each of the three timers. note: please refer to the general interrupt control register description for an explanation of the control fields. t2ic timer 2 intr. ctrl. reg. sfr (ff60 h /b0 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - t2ir t2ie ilvl glvl - - - - - - - - rwh rw rw rw t3ic timer 3 intr. ctrl. reg. sfr (ff62 h /b1 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - t3ir t3ie ilvl glvl - - - - - - - - rwh rw rw rw t4ic timer 4 intr. ctrl. reg. sfr (ff64 h /b2 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - t4ir t4ie ilvl glvl - - - - - - - - rwh rw rw rw
 & !    user ? s manual 10-23 1999-08  10.2 timer block gpt2 from a programmer ? s point of view, the gpt2 block is represented by a set of sfrs as summarized below. those portions of port and direction registers which are used for alternate functions by the gpt2 block are shaded. figure 10-15 sfrs and port pins associated with timer block gpt2 timer block gpt2 supports high precision event control with a maximum resolution of 8 tcl. it includes the two timers t5 and t6, and the 16-bit capture/reload register caprel. timer t6 is referred to as the core timer, and t5 is referred to as the auxiliary timer of gpt2. the count direction (up / down) may be programmed via software. an overflow/ underflow of t6 is indicated by the output toggle bit t6otl. in addition, t6 may be reloaded with the contents of caprel. the toggle bit also supports the concatenation of t6 with auxiliary timer t5. triggered by an external signal, the contents of t5 can be captured into register caprel, and t5 may optionally be cleared. both timer t6 and t5 can count up or down, and the current timer value can be read or modified by the cpu in the non-bitaddressable sfrs t5 and t6. odp3 port 3 open drain control register dp3 port 3 direction control register p3 port 3 data register t5con gpt2 timer 5 control register t6con gpt2 timer 6 control register capin/p3.2 t5con control registers t5 gpt2 timer 5 register t6 gpt2 timer 6 register caprel gpt2 capture/reload register t5ic gpt2 timer 5 interrupt control register t6ic gpt2 timer 6 interrupt control register cric gpt2 caprel interrupt control register ports & direction control alternate functions data registers control registers interrupt control t5 t5ic dp3 p3 t6 caprel t6ic cric t6con odp3e
 & !    user ? s manual 10-24 1999-08  figure 10-16 gpt2 block diagram mux 2 n : 1 f cpu t5 mode control gpt2 timer t5 2 n : 1 f cpu t6 mode control gpt2 timer t6 gpt2 caprel t6otl t3 capin u/d u/d interrupt request interrupt request interrupt request other timers clear capture ct3 mcb03999c.vsd
 & !    user ? s manual 10-25 1999-08  10.2.1 gpt2 core timer t6 the operation of the core timer t6 is controlled by its bitaddressable control register t6con. t6con timer 6 control register sfr (ff48 h /a4 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 t6 sr ---- t6 otl -- t6 ud t6r t6m t6i rw - - - - rwh - - rw rw rw rw bit function t6i timer 6 input selection depends on the operating mode, see respective sections. t6m timer 6 mode control (basic operating mode) 000: timer mode 001: reserved. do not use this combination. 010: reserved. do not use this combination. 011: reserved. do not use this combination. 1xx: reserved. do not use this combination. t6r timer 6 run bit 0: timer / counter 6 stops 1: timer / counter 6 runs t6ud timer 6 up / down control 0: timer / counter 6 counts up 1: timer / counter 6 counts down t6otl timer 6 output toggle latch toggles on each overflow / underflow of t6. can be set or reset by software. t6sr timer 6 reload mode enable 0: reload from register caprel disabled 1: reload from register caprel enabled
 & !    user ? s manual 10-26 1999-08  timer 6 run bit the timer can be started or stopped by software through bit t6r (timer t6 run bit). if t6r= ? 0 ? , the timer stops. setting t6r to ? 1 ? will start the timer. in gated timer mode, the timer will only run if t6r= ? 1 ? and the gate is active (high or low, as programmed). timer 6 output toggle latch an overflow or underflow of timer t6 will clock the toggle bit t6otl in control register t6con. t6otl can also be set or reset by software. t6otl can be used in conjunction with the timer over/underflows as an input for the counter function of the auxiliary timer t5.
 & !    user ? s manual 10-27 1999-08  timer 6 in timer mode timer mode for the core timer t6 is selected by setting bitfield t6m in register t6con to ? 000 b ? . in this mode, t6 is clocked with the internal system clock divided by a programmable prescaler, which is selected by bit field t6i. the input frequency f t6 for timer t6 and its resolution r t6 are scaled linearly with lower clock frequencies f cpu , as can be seen from the following formula: figure 10-17 block diagram of core timer t6 in timer mode the timer input frequencies, resolution and periods which result from the selected prescaler option are listed in the table below. this table also applies to the auxiliary timer t5 in timer mode. note that some numbers may be rounded to 3 significant digits. note: bitfield t6m in register t6con will be ? 000 b ? after reset. do not modify this bitfield to any other value. table 10-7 gpt2 timer input frequencies, resolution and periods f cpu = 20mhz timer input selection t5i / t6i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 4 8 16 32 64 128 256 512 input frequency 5 mhz 2.5 mhz 1.25 mhz 625 khz 312.5 khz 156.25 khz 78.125 khz 39.06 khz resolution 200ns 400 ns 800 ns 1.6 s3.2 s6.4 s12.8 s 25.6 s period 13 ms 26 ms 52.5 ms 105 ms 210 ms 420 ms 840 ms 1.68 s f t6 = f cpu 4 * 2 r t6 [ s] = f cpu [mhz] 4 * 2 core timer tx txotl interrupt request txr 2 n : 1 txl mcb02028c.vsd f cpu up/ down
 & !    user ? s manual 10-28 1999-08  10.2.2 gpt2 auxiliary timer t5 the auxiliary timer t5 can be configured for timer mode with the same options for the timer frequencies as the core timer t6. in addition the auxiliary timer can be concatenated with the core timer (operation in counter mode). its contents may be captured to register caprel upon a selectable trigger. the individual configuration for timer t5 is determined by its bitaddressable control register t5con. note that functions which are present in both timers of block gpt2 are controlled in the same bit positions and in the same manner in each of the specific control registers. note: the auxiliary timer has no output toggle latch and no alternate output function. t5con timer 5 control register sfr (ff46 h /a3 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 t5 sc t5 clr ci - ct3 - t5 ude t5 ud t5r t5m t5i rw rw rw - rw - rw rw rw rw rw bit function t5i timer 5 input selection depends on the operating mode, see respective sections. t5m timer 5 mode control (basic operating mode) 000: timer mode 001: counter mode 01x: reserved. do not use this combination. 1xx: reserved. do not use this combination. t5r timer 5 run bit 0: timer / counter 5 stops 1: timer / counter 5 runs t5ud timer 5 up / down control 0: timer / counter 5 counts up 1: timer / counter 5 counts down ct3 timer 3 capture trigger enable 0: capture trigger from pin capin 1: capture trigger from t3 input pins
 & !    user ? s manual 10-29 1999-08  timer t5 in timer mode when the auxiliary timer t5 is programmed to timer mode, their operation is the same as described for the core timer t6. the descriptions, figures and tables apply accordingly. ci register caprel capture trigger selection (depending on bit ct3) 00: capture disabled 01: positive transition (rising edge) on capin or any transition on t3in 10: negative transition (falling edge) on capin or any transition on t3eud 11: any transition (rising or falling edge) on capin or any transition on t3in or t3eud t5clr timer 5 clear bit 0: timer 5 not cleared on a capture 1: timer 5 is cleared on a capture t5sc timer 5 capture mode enable 0: capture into register caprel disabled 1: capture into register caprel enabled bit function
 & !    user ? s manual 10-30 1999-08  timer t5 in counter mode counter mode for the auxiliary timer t5 is selected by setting bit field t5m in register t5con to ? 001 b ? . in counter mode timer t5 can be clocked by a transition of timer t6 ? s output toggle latch t6otl (i.e. timer concatenation). the event causing an increment or decrement of the timer can be a positive, a negative, or both a positive and a negative transition at the toggle latch t6otl. bit field t5i in control register t5con selects the triggering transition (see table below). note: only state transitions of t6otl which are caused by the overflows/underflows of t6 will trigger the counter function of t5. modifications of t6otl via software will not trigger the counter function of t5. table 10-8 gpt2 auxiliary timer (counter mode) input edge selection t5i triggering edge for counter increment / decrement x 0 0 none. counter t5 is disabled 0 0 1 reserved. do not use this combination. 0 1 0 reserved. do not use this combination. 0 1 1 reserved. do not use this combination. 1 0 1 positive transition (rising edge) of output toggle latch t6otl 1 1 0 negative transition (falling edge) of output toggle latch t6otl 1 1 1 any transition (rising or falling edge) of output toggle latch t6otl
 & !    user ? s manual 10-31 1999-08  timer concatenation using the toggle bit t6otl as a clock source for the auxiliary timer in counter mode concatenates the core timer t6 with the auxiliary timer. depending on which transition of t6otl is selected to clock the auxiliary timer, this concatenation forms a 32-bit or a 33- bit timer / counter.  32-bit timer/counter: if both a positive and a negative transition of t6otl is used to clock the auxiliary timer, this timer is clocked on every overflow/underflow of the core timer t6. thus, the two timers form a 32-bit timer.  33-bit timer/counter: if either a positive or a negative transition of t6otl is selected to clock the auxiliary timer, this timer is clocked on every second overflow/underflow of the core timer t6. this configuration forms a 33-bit timer (16-bit core timer+t6otl+16- bit auxiliary timer). the count directions of the two concatenated timers are not required to be the same. this offers a wide variety of different configurations. figure 10-18 concatenation of core timer t6 and auxiliary timer t5 *) note: line only affected by over/underflows of t6, but not by software modifications of t6otl. x =5 y = 6 core timer ty tyotl interrupt request tyoe tyout tyr 2 n : 1 tyl mcb02034 f cpu up/down auxiliary timer tx txr txl edge select txir interrupt request *) up/down
 & !    user ? s manual 10-32 1999-08  gpt2 capture/reload register caprel in capture mode this 16-bit register can be used as a capture register for the auxiliary timer t5. this mode is selected by setting bit t5sc= ? 1 ? in control register t5con. bit ct3 selects the external input pin capin or the input pins of timer t3 as the source for a capture trigger. either a positive, a negative, or both a positive and a negative transition at pin capin can be selected to trigger the capture function, or transitions on input t3in or input t3eud or both inputs t3in and t3eud. the active edge is controlled by bit field ci in register t5con. the maximum input frequency for the capture trigger signal at capin is f cpu /4. to ensure that a transition of the capture trigger signal is correctly recognized, its level should be held for at least 4 f cpu cycles before it changes. figure 10-19 gpt2 register caprel in capture mode when the timer t3 capture trigger is enabled (ct3= ? 1 ? ) register caprel captures the contents of t5 upon transitions of the selected input(s). these values can be used to measure t3 ? s input signals. this is useful e.g. when t3 operates in incremental interface mode, in order to derive dynamic information (speed acceleration) from the input signals. auxiliary timer t5 edge select mcb02044b.vsd interrupt request capin ci t5sc t5clr input clock up/down interrupt request caprel register m u x t3in/ t3eud ct3
 & !    user ? s manual 10-33 1999-08  when a selected transition at the selected input pin(s) (capin, t3in, t3eud) is detected, the contents of the auxiliary timer t5 are latched into register caprel, and interrupt request flag crir is set. with the same event, timer t5 can be cleared to 0000 h . this option is controlled by bit t5clr in register t5con. if t5clr= ? 0 ? , the contents of timer t5 are not affected by a capture. if t5clr= ? 1 ? , timer t5 is cleared after the current timer value has been latched into register caprel. note: bit t5sc only controls whether a capture is performed or not. if t5sc= ? 0 ? , the selected trigger event can still be used to clear timer t5 or to generate an interrupt request. this interrupt is controlled by the caprel interrupt control register cric. gpt2 capture/reload register caprel in reload mode this 16-bit register can be used as a reload register for the core timer t6. this mode is selected by setting bit t6sr= ? 1 ? in register t6con. the event causing a reload in this mode is an overflow or underflow of the core timer t6. when timer t6 overflows from ffff h to 0000 h (when counting up) or when it underflows from 0000 h to ffff h (when counting down), the value stored in register caprel is loaded into timer t6. this will not set the interrupt request flag crir associated with the caprel register. however, interrupt request flag t6ir will be set indicating the overflow/underflow of t6. figure 10-20 gpt2 register caprel in reload mode core timer t6 up/down interrupt request input clock mcb02045b.vsd t6otl t6sr caprel register
 & !    user ? s manual 10-34 1999-08  gpt2 capture/reload register caprel in capture-and-reload mode since the reload function and the capture function of register caprel can be enabled individually by bits t5sc and t6sr, the two functions can be enabled simultaneously by setting both bits. this feature can be used to generate an output frequency that is a multiple of the input frequency. figure 10-21 gpt2 register caprel in capture-and-reload mode this combined mode can be used to detect consecutive external events which may occur aperiodically, but where a finer resolution, that means, more ? ticks ? within the time between two external events is required. for this purpose, the time between the external events is measured using timer t5 and the caprel register. timer t5 runs in timer mode counting up with a frequency of e.g. f cpu /32. the external events are applied to pin capin. when an external event occurs, the timer t5 contents are latched into register caprel, and timer t5 is cleared (t5clr= ? 1 ? ). thus, register caprel always contains the correct time between two auxiliary timer t5 edge select mcb02046c.vsd interrupt request ci t5sc t5clr input clock up/down interrupt request caprel register t6otl core timer t6 interrupt request input clock t6sr up/down capin m u x t3in/ t3eud ct3
 & !    user ? s manual 10-35 1999-08  events, measured in timer t5 increments. timer t6, which runs in timer mode counting down with a frequency of e.g. f cpu /4, uses the value in register caprel to perform a reload on underflow. this means, the value in register caprel represents the time between two underflows of timer t6, now measured in timer t6 increments. since timer t6 runs 8 times faster than timer t5, it will underflow 8 times within the time between two external events. thus, the underflow signal of timer t6 generates 8 ? ticks ? . upon each underflow, the interrupt request flag t6ir will be set and bit t6otl will be toggled.
 & !    user ? s manual 10-36 1999-08  10.2.3 interrupt control for gpt2 timers and caprel when a timer overflows from ffff h to 0000 h (when counting up), or when it underflows from 0000 h to ffff h (when counting down), its interrupt request flag (t5ir or t6ir) in register txic will be set. whenever a transition according to the selection in bit field ci is detected at pin capin, interrupt request flag crir in register cric is set. setting any request flag will cause an interrupt to the respective timer or caprel interrupt vector (t5int, t6int or crint) or trigger a pec service, if the respective interrupt enable bit (t5ie or t6ie in register txic, crie in register cric) is set. there is an interrupt control register for each of the two timers and for the caprel register. note: please refer to the general interrupt control register description for an explanation of the control fields. t5ic timer 5 intr. ctrl. reg. sfr (ff66 h /b3 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - t5ir t5ie ilvl glvl - - - - - - - - rwh rw rw rw t6ic timer 6 intr. ctrl. reg. sfr (ff68 h /b4 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - t6ir t6ie ilvl glvl - - - - - - - - rwh rw rw rw cric caprel intr. ctrl. reg. sfr (ff6a h /b5 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - crir crie ilvl glvl - - - - - - - - rwh rw rw rw
    2#   # 1  user ? s manual 11-1 1999-08  11 the asynchronous/synchronous serial interface the asynchronous/synchronous serial interface asc0 provides serial communication between the c161pi and other microcontrollers, microprocessors or external peripherals. the asc0 supports full-duplex asynchronous communication up to 780 kbaud and half- duplex synchronous communication up to 3.1 mbaud (@ 25 mhz cpu clock). in synchronous mode, data are transmitted or received synchronous to a shift clock which is generated by the c161pi. in asynchronous mode, 8- or 9-bit data transfer, parity generation, and the number of stop bits can be selected. parity, framing, and overrun error detection is provided to increase the reliability of data transfers. transmission and reception of data is double-buffered. for multiprocessor communication, a mechanism to distinguish address from data bytes is included. testing is supported by a loop-back option. a 13-bit baud rate generator provides the asc0 with a separate serial clock signal. figure 11-1 sfrs and port pins associated with asc0 s0tic s0tbic e rxd0 / p3.11 txd0 / p3.10 odp3 port 3 open drain control register dp3 port 3 direction control register s0bg asc0 baud rate generator/reload reg. s0tbuf asc0 transmit buffer register s0tic asc0 transmit interrupt control register s0tbic asc0 transmit buffer interrupt ctrl. reg. p3 port 3 data register s0con asc0 control register s0rbuf asc0 receive buffer register (read only) s0ric asc0 receive interrupt control register s0eic asc0 error interrupt control register odp3 e ports & direction control alternate functions data registers control registers interrupt control s0bg s0con dp3 p3 s0tbuf s0rbuf s0ric s0eic
    2#   # 1  user ? s manual 11-2 1999-08  the operating mode of the serial channel asc0 is controlled by its bitaddressable control register s0con. this register contains control bits for mode and error check selection, and status flags for error identification. s0con asc0 control register sfr (ffb0 h /d8 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 s0r s0 lb s0 brs s0 odd - s0 oe s0 fe s0 pe s0 oen s0 fen pen s0 ren s0 stp s0m rw rw rw rw - rwh rwh rwh rw rw rw rwh rw rw bit function s0m asc0 mode control 000: 8-bit data synchronous operation 001: 8-bit data async. operation 010: reserved. do not use this combination! 011: 7-bit data + parity async. operation 100: 9-bit data async. operation 101: 8-bit data + wake up bit async. operation 110: reserved. do not use this combination! 111: 8-bit data + parity async. operation s0stp number of stop bits selection async. operation 0: one stop bit 1: two stop bits s0ren receiver enable bit 0: receiver disabled 1: receiver enabled (reset by hardware after reception of byte in synchronous mode) s0pen parity check enable bit async. operation 0: ignore parity 1: check parity s0fen framing check enable bit async. operation 0: ignore framing errors 1: check framing errors s0oen overrun check enable bit 0: ignore overrun errors 1: check overrun errors s0pe parity error flag set by hardware on a parity error (s0pen= ? 1 ? ). must be reset by software.
    2#   # 1  user ? s manual 11-3 1999-08  a transmission is started by writing to the transmit buffer register s0tbuf (via an instruction or a pec data transfer). only the number of data bits which is determined by the selected operating mode will actually be transmitted, i.e. bits written to positions 9 through 15 of register s0tbuf are always insignificant. after a transmission has been completed, the transmit buffer register is cleared to 0000 h . data transmission is double-buffered, so a new character may be written to the transmit buffer register, before the transmission of the previous character is complete. this allows the transmission of characters back-to-back without gaps. data reception is enabled by the receiver enable bit s0ren. after reception of a character has been completed, the received data and, if provided by the selected operating mode, the received parity bit can be read from the (read-only) receive buffer register s0rbuf. bits in the upper half of s0rbuf which are not valid in the selected operating mode will be read as zeros. data reception is double-buffered, so that reception of a second character may already begin before the previously received character has been read out of the receive buffer register. in all modes, receive buffer overrun error detection can be selected through bit s0oen. when enabled, the overrun error status flag s0oe and the error interrupt request flag s0eir will be set when the receive buffer register has not been read by the time reception of a second character is complete. the previously received character in the receive buffer is overwritten. s0fe framing error flag set by hardware on a framing error (s0fen= ? 1 ? ). must be reset by software. s0oe overrun error flag set by hardware on an overrun error (s0oen= ? 1 ? ). must be reset by software. s0odd parity selection bit 0: even parity (parity bit set on odd number of ? 1 ? s in data) 1: odd parity (parity bit set on even number of ? 1 ? s in data) s0brs baudrate selection bit 0: divide clock by reload-value + constant (depending on mode) 1: additionally reduce serial clock to 2/3rd s0lb loopback mode enable bit 0: standard transmit/receive mode 1: loopback mode enabled s0r baudrate generator run bit 0: baudrate generator disabled (asc0 inactive) 1: baudrate generator enabled bit function
    2#   # 1  user ? s manual 11-4 1999-08  the loop-back option (selected by bit s0lb) allows the data currently being transmitted to be received simultaneously in the receive buffer. this may be used to test serial communication routines at an early stage without having to provide an external network. in loop-back mode the alternate input/output functions of the port 3 pins are not necessary. note: serial data transmission or reception is only possible when the baud rate generator run bit s0r is set to ? 1 ? . otherwise the serial interface is idle. do not program the mode control field s0m in register s0con to one of the reserved combinations to avoid unpredictable behaviour of the serial interface.
    2#   # 1  user ? s manual 11-5 1999-08  11.1 asynchronous operation asynchronous mode supports full-duplex communication, where both transmitter and receiver use the same data frame format and the same baud rate. data is transmitted on pin txd0 and received on pin rxd0. these signals are alternate port functions. asynchronous data frames 8-bit data frames either consist of 8 data bits d7...d0 (s0m= ? 001 b ? ), or of 7 data bits d6...d0 plus an automatically generated parity bit (s0m= ? 011 b ? ). parity may be odd or even, depending on bit s0odd in register s0con. an even parity bit will be set, if the modulo-2-sum of the 7 data bits is ? 1 ? . an odd parity bit will be cleared in this case. parity checking is enabled via bit s0pen (always off in 8-bit data mode). the parity error flag s0pe will be set along with the error interrupt request flag, if a wrong parity bit is received. the parity bit itself will be stored in bit s0rbuf.7. figure 11-2 asynchronous mode of serial channel asc0
    2#   # 1  user ? s manual 11-6 1999-08  figure 11-3 asynchronous 8-bit data frames 9-bit data frames either consist of 9 data bits d8...d0 (s0m= ? 100 b ? ), of 8 data bits d7...d0 plus an automatically generated parity bit (s0m= ? 111 b ? ) or of 8 data bits d7...d0 plus wake-up bit (s0m= ? 101 b ? ). parity may be odd or even, depending on bit s0odd in register s0con. an even parity bit will be set, if the modulo-2-sum of the 8 data bits is ? 1 ? . an odd parity bit will be cleared in this case. parity checking is enabled via bit s0pen (always off in 9-bit data and wake-up mode). the parity error flag s0pe will be set along with the error interrupt request flag, if a wrong parity bit is received. the parity bit itself will be stored in bit s0rbuf.8. in wake-up mode received frames are only transferred to the receive buffer register, if the 9th bit (the wake-up bit) is ? 1 ? . if this bit is ? 0 ? , no receive interrupt request will be activated and no data will be transferred. this feature may be used to control communication in multi-processor system: when the master processor wants to transmit a block of data to one of several slaves, it first sends out an address byte which identifies the target slave. an address byte differs from a data byte in that the additional 9th bit is a '1' for an address byte and a '0' for a data byte, so no slave will be interrupted by a data 'byte'. an address 'byte' will interrupt all slaves (operating in 8-bit data + wake-up bit mode), so each slave can examine the 8 lsbs of the received character (the address). the addressed slave will switch to 9-bit data mode (e.g. by clearing bit s0m.0), which enables it to also receive the data bytes that will be coming (having the wake-up bit cleared). the slaves that were not being addressed remain in 8-bit data + wake-up bit mode, ignoring the following data bytes. figure 11-4 asynchronous 9-bit data frames 2nd stop bit start bit d0 (lsb) d1 d2 d3 d4 d5 d6 d7 / parity (1st) stop bit 2nd stop bit start bit d0 (lsb) d1 d2 d3 d4 d5 d6 9th bit (1st) stop bit d7  data bit d8  parity  wake-up bit
    2#   # 1  user ? s manual 11-7 1999-08  asynchronous transmission begins at the next overflow of the divide-by-16 counter (see figure above), provided that s0r is set and data has been loaded into s0tbuf. the transmitted data frame consists of three basic elements:  the start bit  the data field (8 or 9 bits, lsb first, including a parity bit, if selected)  the delimiter (1 or 2 stop bits) data transmission is double buffered. when the transmitter is idle, the transmit data loaded into s0tbuf is immediately moved to the transmit shift register thus freeing s0tbuf for the next data to be sent. this is indicated by the transmit buffer interrupt request flag s0tbir being set. s0tbuf may now be loaded with the next data, while transmission of the previous one is still going on. the transmit interrupt request flag s0tir will be set before the last bit of a frame is transmitted, i.e. before the first or the second stop bit is shifted out of the transmit shift register. the transmitter output pin txd0 must be configured for alternate data output, i.e. the respective port output latch and the direction latch must be ? 1 ? . asynchronous reception is initiated by a falling edge (1-to-0 transition) on pin rxd0, provided that bits s0r and s0ren are set. the receive data input pin rxd0 is sampled at 16 times the rate of the selected baud rate. a majority decision of the 7th, 8th and 9th sample determines the effective bit value. this avoids erroneous results that may be caused by noise. if the detected value is not a '0' when the start bit is sampled, the receive circuit is reset and waits for the next 1-to-0 transition at pin rxd0. if the start bit proves valid, the receive circuit continues sampling and shifts the incoming data frame into the receive shift register. when the last stop bit has been received, the content of the receive shift register is transferred to the receive data buffer register s0rbuf. simultaneously, the receive interrupt request flag s0rir is set after the 9th sample in the last stop bit time slot (as programmed), regardless whether valid stop bits have been received or not. the receive circuit then waits for the next start bit (1-to-0 transition) at the receive data input pin. the receiver input pin rxd0 must be configured for input, i.e. the respective direction latch must be ? 0 ? . asynchronous reception is stopped by clearing bit s0ren. a currently received frame is completed including the generation of the receive interrupt request and an error interrupt request, if appropriate. start bits that follow this frame will not be recognized. note: in wake-up mode received frames are only transferred to the receive buffer register, if the 9th bit (the wake-up bit) is ? 1 ? . if this bit is ? 0 ? , no receive interrupt request will be activated and no data will be transferred.
    2#   # 1  user ? s manual 11-8 1999-08  11.2 synchronous operation synchronous mode supports half-duplex communication, basically for simple io expansion via shift registers. data is transmitted and received via pin rxd0, while pin txd0 outputs the shift clock. these signals are alternate port functions. synchronous mode is selected with s0m= ? 000 b ? . 8 data bits are transmitted or received synchronous to a shift clock generated by the internal baud rate generator. the shift clock is only active as long as data bits are transmitted or received. figure 11-5 synchronous mode of serial channel asc0
    2#   # 1  user ? s manual 11-9 1999-08  synchronous transmission begins within 4 state times after data has been loaded into s0tbuf, provided that s0r is set and s0ren= ? 0 ? (half-duplex, no reception). data transmission is double buffered. when the transmitter is idle, the transmit data loaded into s0tbuf is immediately moved to the transmit shift register thus freeing s0tbuf for the next data to be sent. this is indicated by the transmit buffer interrupt request flag s0tbir being set. s0tbuf may now be loaded with the next data, while transmission of the previous one is still going on. the data bits are transmitted synchronous with the shift clock. after the bit time for the 8th data bit, both pins txd0 and rxd0 will go high, the transmit interrupt request flag s0tir is set, and serial data transmission stops. pin txd0 must be configured for alternate data output, i.e. the respective port output latch and the direction latch must be ? 1 ? , in order to provide the shift clock. pin rxd0 must also be configured for output (output/direction latch= ? 1 ? ) during transmission. synchronous reception is initiated by setting bit s0ren= ? 1 ? . if bit s0r=1, the data applied at pin rxd0 are clocked into the receive shift register synchronous to the clock which is output at pin txd0. after the 8th bit has been shifted in, the content of the receive shift register is transferred to the receive data buffer s0rbuf, the receive interrupt request flag s0rir is set, the receiver enable bit s0ren is reset, and serial data reception stops. pin txd0 must be configured for alternate data output, i.e. the respective port output latch and the direction latch must be ? 1 ? , in order to provide the shift clock. pin rxd0 must be configured as alternate data input, i.e. the respective direction latch must be ? 0 ? . synchronous reception is stopped by clearing bit s0ren. a currently received byte is completed including the generation of the receive interrupt request and an error interrupt request, if appropriate. writing to the transmit buffer register while a reception is in progress has no effect on reception and will not start a transmission. if a previously received byte has not been read out of the receive buffer register at the time the reception of the next byte is complete, both the error interrupt request flag s0eir and the overrun error status flag s0oe will be set, provided the overrun check has been enabled by bit s0oen.
    2#   # 1  user ? s manual 11-10 1999-08  11.3 hardware error detection capabilities to improve the safety of serial data exchange, the serial channel asc0 provides an error interrupt request flag, which indicates the presence of an error, and three (selectable) error status flags in register s0con, which indicate which error has been detected during reception. upon completion of a reception, the error interrupt request flag s0eir will be set simultaneously with the receive interrupt request flag s0rir, if one or more of the following conditions are met:  if the framing error detection enable bit s0fen is set and any of the expected stop bits is not high, the framing error flag s0fe is set, indicating that the error interrupt request is due to a framing error (asynchronous mode only).  if the parity error detection enable bit s0pen is set in the modes where a parity bit is received, and the parity check on the received data bits proves false, the parity error flag s0pe is set, indicating that the error interrupt request is due to a parity error (asynchronous mode only).  if the overrun error detection enable bit s0oen is set and the last character received was not read out of the receive buffer by software or pec transfer at the time the reception of a new frame is complete, the overrun error flag s0oe is set indicating that the error interrupt request is due to an overrun error (asynchronous and synchronous mode).
    2#   # 1  user ? s manual 11-11 1999-08  11.4 asc0 baud rate generation the serial channel asc0 has its own dedicated 13-bit baud rate generator with 13-bit reload capability, allowing baud rate generation independent of the gpt timers. the baud rate generator is clocked with the cpu clock divided by 2 ( f cpu /2). the timer is counting downwards and can be started or stopped through the baud rate generator run bit s0r in register s0con. each underflow of the timer provides one clock pulse to the serial channel. the timer is reloaded with the value stored in its 13-bit reload register each time it underflows. the resulting clock is again divided according to the operating mode and controlled by the baudrate selection bit s0brs. if s0brs= ? 1 ? , the clock signal is additionally divided to 2/3rd of its frequency (see formulas and table). so the baud rate of asc0 is determined by the cpu clock, the reload value, the value of s0brs and the operating mode (asynchronous or synchronous). register s0bg is the dual-function baud rate generator/reload register. reading s0bg returns the content of the timer (bits 15...13 return zero), while writing to s0bg always updates the reload register (bits 15...13 are insiginificant). an auto-reload of the timer with the content of the reload register is performed each time s0bg is written to. however, if s0r= ? 0 ? at the time the write operation to s0bg is performed, the timer will not be reloaded until the first instruction cycle after s0r= ? 1 ? . asynchronous mode baud rates for asynchronous operation, the baud rate generator provides a clock with 16 times the rate of the established baud rate. every received bit is sampled at the 7th, 8th and 9th cycle of this clock. the baud rate for asynchronous operation of serial channel asc0 and the required reload value for a given baudrate can be determined by the following formulas: represents the content of the reload register, taken as unsigned 13-bit integer, represents the value of bit s0brs (i.e. ? 0 ? or ? 1 ? ), taken as integer. the tables below list various commonly used baud rates together with the required reload values and the deviation errors compared to the intended baudrate for a number of cpu frequencies. note: the deviation errors given in the tables below are rounded. using a baudrate crystal (e.g. 18.432 mhz) will provide correct baudrates without deviation errors. b async = f cpu 16 * (2 + ) * ( + 1) s0brl = ( f cpu 16 * (2 + ) * b async ) - 1
    2#   # 1  user ? s manual 11-12 1999-08  table 11-1 asc0 asynchronous baudrate generation for f cpu = 25 mhz baud rate s0brs = ? 0 ? s0brs = ? 1 ? deviation error reload value deviation error reload value 780 kbaud + 0.2 % 0000 h --- --- 19.2 kbaud +1.7 % / -0.8 % 0027 h / 0028 h +0.5 % / -3.1 % 001a h / 001b h 9600 baud +0.5 % / -0.8 % 0050 h / 0051 h +0.5 % / -1.4 % 0035 h / 0036 h 4800 baud +0.5 % / -0.2 % 00a1 h / 00a2 h +0.5 % / -0.5 % 006b h / 006c h 2400 baud +0.2 % / -0.2 % 0145 h / 0146 h +0.0 % / -0.5 % 00d8 h / 00d9 h 1200 baud +0.0 % / -0.2 % 028a h / 028b h +0.0 % / -0.2 % 01b1 h / 01b2 h 600 baud +0.0 % / -0.1 % 0515 h / 0516 h +0.0 % / -0.1 % 0363 h / 0364 h 95 baud +0.4 % 1fff h +0.0 % / -0.0 % 1569 h / 156a h 63 baud --- --- +1.0 % 1fff h table 11-2 asc0 asynchronous baudrate generation for f cpu = 20 mhz baud rate s0brs = ? 0 ? s0brs = ? 1 ? deviation error reload value deviation error reload value 625 kbaud 0.0 % 0000 h --- --- 19.2 kbaud +1.7 % / -1.4 % 001f h / 0020 h +3.3 % / -1.4 % 0014 h / 0015 h 9600 baud +0.2 % / -1.4 % 0040 h / 0041 h +1.0 % / -1.4 % 002a h / 002b h 4800 baud +0.2 % / -0.6 % 0081 h / 0082 h +1.0 % / -0.2 % 0055 h / 0056 h 2400 baud +0.2 % / -0.2 % 0103 h / 0104 h +0.4 % / -0.2 % 00ac h / 00ad h 1200 baud +0.2 % / -0.4 % 0207 h / 0208 h +0.1 % / -0.2 % 015a h / 015b h 600 baud +0.1 % / -0.0 % 0410 h / 0411 h +0.1 % / -0.1 % 02b5 h / 02b6 h 75 baud +1.7 % 1fff h +0.0 % / -0.0 % 15b2 h / 15b3 h 50 baud --- --- +1.7 % 1fff h
    2#   # 1  user ? s manual 11-13 1999-08  table 11-3 asc0 asynchronous baudrate generation for f cpu = 16 mhz baud rate s0brs = ? 0 ? s0brs = ? 1 ? deviation error reload value deviation error reload value 500 kbaud 0.0 % 0000 h --- --- 19.2 kbaud +0.2 % / -3.5 % 0019 h / 001a h +2.1 % / -3.5 % 0010 h / 0011 h 9600 baud +0.2 % / -1.7 % 0033 h / 0034 h +2.1 % / -0.8 % 0021 h / 0022 h 4800 baud +0.2 % / -0.8 % 0067 h / 0068 h +0.6 % / -0.8 % 0044 h / 0045 h 2400 baud +0.2 % / -0.3 % 00cf h / 00d0 h +0.6 % / -0.1 % 0089 h / 008a h 1200 baud +0.4 % / -0.1 % 019f h / 01a0 h +0.3 % / -0.1 % 0114 h / 0115 h 600 baud +0.0 % / -0.1 % 0340 h / 0341 h +0.1 % / -0.1 % 022a h / 022b h 61 baud +0.1 % 1fff h +0.0 % / -0.0 % 115b h / 115c h 40 baud --- --- +1.7 % 1fff h
    2#   # 1  user ? s manual 11-14 1999-08  synchronous mode baud rates for synchronous operation, the baud rate generator provides a clock with 4 times the rate of the established baud rate. the baud rate for synchronous operation of serial channel asc0 can be determined by the following formula: represents the content of the reload register, taken as unsigned 13-bit integers, represents the value of bit s0brs (i.e. ? 0 ? or ? 1 ? ), taken as integer. the table below gives the limit baudrates depending on the cpu clock frequency and bit s0brs. table 11-4 asc0 synchronous baudrate generation cpu clock f cpu s0brs = ? 0 ? s0brs = ? 1 ? min. baudrate max. baudrate min. baudrate max. baudrate 16 mhz 244 baud 2.000 mbaud 162 baud 1.333 mbaud 20 mhz 305 baud 2.500 mbaud 203 baud 1.666 mbaud 25 mhz 381 baud 3.125 mbaud 254 baud 2.083 mbaud b sync = s0brl = ( f cpu 4 * (2 + ) * b sync ) - 1 f cpu 4 * (2 + ) * ( + 1)
    2#   # 1  user ? s manual 11-15 1999-08  11.5 asc0 interrupt control four bit addressable interrupt control registers are provided for serial channel asc0. register s0tic controls the transmit interrupt, s0tbic controls the transmit buffer interrupt, s0ric controls the receive interrupt and s0eic controls the error interrupt of serial channel asc0. each interrupt source also has its own dedicated interrupt vector. s0tint is the transmit interrupt vector, s0tbint is the transmit buffer interrupt vector, s0rint is the receive interrupt vector, and s0eint is the error interrupt vector. the cause of an error interrupt request (framing, parity, overrun error) can be identified by the error status flags in control register s0con. note: in contrast to the error interrupt request flag s0eir, the error status flags s0fe/ s0pe/s0oe are not reset automatically upon entry into the error interrupt service routine, but must be cleared by software. s0tic asc0 tx intr. ctrl. reg. sfr (ff6c h /b6 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - s0 tir s0 tie ilvl glvl -------- rwh rw rw rw s0tbic asc0 tx buf. intr. ctrl. reg. sfr (ff9c h /ce h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - s0 tbir s0 tbie ilvl glvl -------- rwh rw rw rw s0ric asc0 rx intr. ctrl. reg. sfr (ff6e h /b7 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - s0 rir s0 rie ilvl glvl -------- rwh rw rw rw
    2#   # 1  user ? s manual 11-16 1999-08  note: please refer to the general interrupt control register description for an explanation of the control fields. using the asc0 interrupts for normal operation (i.e. besides the error interrupt) the asc0 provides three interrupt requests to control data exchange via this serial channel:  s0tbir is activated when data is moved from s0tbuf to the transmit shift register.  s0tir is activated before the last bit of an asynchronous frame is transmitted, or after the last bit of a synchronous frame has been transmitted.  s0rir is activated when the received frame is moved to s0rbuf. while the task of the receive interrupt handler is quite clear, the transmitter is serviced by two interrupt handlers. this provides advantages for the servicing software. for single transfers is is sufficient to use the transmitter interrupt (s0tir), which indicates that the previously loaded data has been transmitted, except for the last bit of an asynchronous frame. for multiple back-to-back transfers it is necessary to load the following piece of data at last until the time the last bit of the previous frame has been transmitted. in asynchronous mode this leaves just one bit-time for the handler to respond to the transmitter interrupt request, in synchronous mode it is impossible at all. using the transmit buffer interrupt (s0tbir) to reload transmit data gives the time to transmit a complete frame for the service routine, as s0tbuf may be reloaded while the previous data is still being transmitted. s0eic asc0 error intr. ctrl. reg. sfr (ff70 h /b8 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - s0 eir s0 eie ilvl glvl -------- rwh rw rw rw
    2#   # 1  user ? s manual 11-17 1999-08  figure 11-6 asc0 interrupt generation as shown in the figure above, s0tbir is an early trigger for the reload routine, while s0tir indicates the completed transmission. software using handshake therefore should rely on s0tir at the end of a data block to make sure that all data has really been transmitted. idle idle start start start stop stop stop s0tbir s0tbir s0tbir s0tir s0tir s0tir s0rir s0rir s0rir idle idle s0tbir s0tbir s0tbir s0tir s0tir s0tir s0rir s0rir s0rir asynchronous mode synchronous mode
    2#   # 1  user ? s manual 11-18 1999-08 
 3 4#!
#   # 1  user ? s manual 12-1 1999-08  12 the high-speed synchronous serial interface the high-speed synchronous serial interface ssc provides flexible high-speed serial communication between the c161pi and other microcontrollers, microprocessors or external peripherals. the ssc supports full-duplex and half-duplex synchronous communication up to 6.25 mbaud (@ 25 mhz cpu clock). the serial clock signal can be generated by the ssc itself (master mode) or be received from an external master (slave mode). data width, shift direction, clock polarity and phase are programmable. this allows communication with spi-compatible devices. transmission and reception of data is double-buffered. a 16-bit baud rate generator provides the ssc with a separate serial clock signal. the high-speed synchronous serial interface can be configured in a very flexible way, so it can be used with other synchronous serial interfaces (e.g. the asc0 in synchronous mode), serve for master/slave or multimaster interconnections or operate compatible with the popular spi interface. so it can be used to communicate with shift registers (io expansion), peripherals (e.g. eeproms etc.) or other controllers (networking). the ssc supports half-duplex and full-duplex communication. data is transmitted or received on pins mtsr/p3.9 (master transmit / slave receive) and mrst/p3.8 (master receive / slave transmit). the clock signal is output or input on pin sclk/p3.13. these pins are alternate functions of port 3 pins. figure 12-1 sfrs and port pins associated with the ssc sclk / p3.13 mtsr / p3.9 mrst / p3.8 odp3port 3 open drain control register dp3port 3 direction control register sscbrssc baud rate generator/reload reg. ssctbssc transmit buffer register sscticssc transmit interrupt control register p3 port 3 data register sscconssc control register sscrbssc receive buffer register sscricssc receive interrupt control register ssceicssc error interrupt control register odp3 e ports & direction control alternate functions data registers control registers interrupt control sscbr e ssccon ssctic dp3 p3 ssctb e sscrb e sscric ssceic
 3 4#!
#   # 1  user ? s manual 12-2 1999-08  figure 12-2 synchronous serial channel ssc block diagram the operating mode of the serial channel ssc is controlled by its bit-addressable control register ssccon. this register serves for two purposes:  during programming (ssc disabled by sscen= ? 0 ? ) it provides access to a set of ctrl. bits,  during operation (ssc enabled by sscen= ? 1 ? ) it provides access to a set of status flags. register ssccon is shown below in each of the two modes.
 3 4#!
#   # 1  user ? s manual 12-3 1999-08  ssccon ssc control reg. (pr.m.) sfr (ffb2 h /d9 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ssc en =0 ssc ms - ssc ar en ssc ben ssc pen ssc ren ssc ten - ssc po ssc ph ssc hb sscbm rw rw - rw rw rw rw rw rw rw rw rw rw bit function (programming mode, sscen = ? 0 ? ) sscbm ssc data width selection 0: reserved. do not use this combination. 1..15: transfer data width is 2...16 bit (+1) sschb ssc heading control bit 0: transmit/receive lsb first 1: transmit/receive msb first sscph ssc clock phase control bit 0: shift transmit data on the leading clock edge, latch on trailing edge 1: latch receive data on leading clock edge, shift on trailing edge sscpo ssc clock polarity control bit 0: idle clock line is low, leading clock edge is low-to-high transition 1: idle clock line is high, leading clock edge is high-to-low transition sscten ssc transmit error enable bit 0: ignore transmit errors 1: check transmit errors sscren ssc receive error enable bit 0: ignore receive errors 1: check receive errors sscpen ssc phase error enable bit 0: ignore phase errors 1: check phase errors sscben ssc baudrate error enable bit 0: ignore baudrate errors 1: check baudrate errors sscaren ssc automatic reset enable bit 0: no additional action upon a baudrate error 1: the ssc is automatically reset upon a baudrate error sscms ssc master select bit 0: slave mode. operate on shift clock received via sclk. 1: master mode. generate shift clock and output it via sclk. sscen ssc enable bit = ? 0 ? transmission and reception disabled. access to control bits.
 3 4#!
#   # 1  user ? s manual 12-4 1999-08  note:  the target of an access to ssccon (control bits or flags) is determined by the state of sscen prior to the access, i.e. writing c057 h to ssccon in programming mode (sscen= ? 0 ? ) will initialize the ssc (sscen was ? 0 ? ) and then turn it on (sscen= ? 1 ? ).  when writing to ssccon, make sure that reserved locations receive zeros. ssccon ssc control reg. (op.m.) sfr (ffb2 h /d9 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ssc en =1 ssc ms - ssc bsy ssc be ssc pe ssc re ssc te ---- sscbc rw rw - rw rw rw rw rw - - - - r bit function (operating mode, sscen = ? 1 ? ) sscbc ssc bit count field shift counter is updated with every shifted bit. do not write to!!! sscte ssc transmit error flag 1: transfer starts with the slave ? s transmit buffer not being updated sscre ssc receive error flag 1: reception completed before the receive buffer was read sscpe ssc phase error flag 1: received data changes around sampling clock edge sscbe ssc baudrate error flag 1: more than factor 2 or less than factor 0.5 between slave ? s actual and expected baudrate sscbsy ssc busy flag set while a transfer is in progress. do not write to!!! sscms ssc master select bit 0: slave mode. operate on shift clock received via sclk. 1: master mode. generate shift clock and output it via sclk. sscen ssc enable bit = ? 1 ? transmission and reception enabled. access to status flags and m/s control.
 3 4#!
#   # 1  user ? s manual 12-5 1999-08  the shift register of the ssc is connected to both the transmit pin and the receive pin via the pin control logic (see block diagram). transmission and reception of serial data is synchronized and takes place at the same time, i.e. the number of transmitted bits is also received. transmit data is written into the transmit buffer ssctb. it is moved to the shift register as soon as this is empty. an ssc-master (sscms= ? 1 ? ) immediately begins transmitting, while an ssc-slave (sscms= ? 0 ? ) will wait for an active shift clock. when the transfer starts, the busy flag sscbsy is set and a transmit interrupt request (ssctir) will be generated to indicate that ssctb may be reloaded again. when the programmed number of bits (2...16) has been transferred, the contents of the shift register are moved to the receive buffer sscrb and a receive interrupt request (sscrir) will be generated. if no further transfer is to take place (ssctb is empty), sscbsy will be cleared at the same time. software should not modify sscbsy, as this flag is hardware controlled. note: only one ssc (etc.) can be master at a given time. the transfer of serial data bits can be programmed in many respects:  the data width can be chosen from 2 bits to 16 bits  transfer may start with the lsb or the msb  the shift clock may be idle low or idle high  data bits may be shifted with the leading or trailing edge of the clock signal  the baudrate may be set within a wide range (see baudrate generation)  the shift clock can be generated (master) or received (slave) this allows the adaptation of the ssc to a wide range of applications, where serial data transfer is required. the data width selection supports the transfer of frames of any length, from 2-bit ? characters ? up to 16-bit ? characters ? . starting with the lsb (sschb= ? 0 ? ) allows communication e.g. with asc0 devices in synchronous mode (c166 family) or 8051 like serial interfaces. starting with the msb (sschb= ? 1 ? ) allows operation compatible with the spi interface. regardless which data width is selected and whether the msb or the lsb is transmitted first, the transfer data is always right aligned in registers ssctb and sscrb, with the lsb of the transfer data in bit 0 of these registers. the data bits are rearranged for transfer by the internal shift register logic. the unselected bits of ssctb are ignored, the unselected bits of sscrb will be not valid and should be ignored by the receiver service routine. the clock control allows the adaptation of transmit and receive behaviour of the ssc to a variety of serial interfaces. a specific clock edge (rising or falling) is used to shift out transmit data, while the other clock edge is used to latch in receive data. bit sscph selects the leading edge or the trailing edge for each function. bit sscpo selects the level of the clock line in the idle state. so for an idle-high clock the leading edge is a falling one, a 1-to-0 transition. the figure below is a summary.
 3 4#!
#   # 1  user ? s manual 12-6 1999-08  figure 12-3 serial clock phase and polarity options
 3 4#!
#   # 1  user ? s manual 12-7 1999-08  12.1 full-duplex operation the different devices are connected through three lines. the definition of these lines is always determined by the master: the line connected to the master ? s data output pin mtsr is the transmit line, the receive line is connected to its data input line mrst, and the clock line is connected to pin sclk. only the device selected for master operation generates and outputs the serial clock on pin sclk. all slaves receive this clock, so their pin sclk must be switched to input mode (dp3.13= ? 0 ? ). the output of the master ? s shift register is connected to the external transmit line, which in turn is connected to the slaves ? shift register input. the output of the slaves ? shift register is connected to the external receive line in order to enable the master to receive the data shifted out of the slave. the external connections are hard-wired, the function and direction of these pins is determined by the master or slave operation of the individual device. note: the shift direction shown in the figure applies for msb-first operation as well as for lsb-first operation. when initializing the devices in this configuration, select one device for master operation (sscms= ? 1 ? ), all others must be programmed for slave operation (sscms= ? 0 ? ). initialization includes the operating mode of the device's ssc and also the function of the respective port lines (see ? port control ? ). figure 12-4 ssc full duplex configuration mcs01963 mrst sclk device #2 slave clock shift register mtsr clock master receive transmit device #1 clock mtsr mrst sclk shift register mtsr shift register clock slave sclk mrst device #3
 3 4#!
#   # 1  user ? s manual 12-8 1999-08  the data output pins mrst of all slave devices are connected together onto the one receive line in this configuration. during a transfer each slave shifts out data from its shift register. there are two ways to avoid collisions on the receive line due to different slave data: only one slave drives the line , i.e. enables the driver of its mrst pin. all the other slaves have to program their mrst pins to input. so only one slave can put its data onto the master ? s receive line. only receiving of data from the master is possible. the master selects the slave device from which it expects data either by separate select lines, or by sending a special command to this slave. the selected slave then switches its mrst line to output, until it gets a deselection signal or command. the slaves use open drain output on mrst . this forms a wired-and connection. the receive line needs an external pullup in this case. corruption of the data on the receive line sent by the selected slave is avoided, when all slaves which are not selected for transmission to the master only send ones ( ? 1 ? ). since this high level is not actively driven onto the line, but only held through the pullup device, the selected slave can pull this line actively to a low level when transmitting a zero bit. the master selects the slave device from which it expects data either by separate select lines, or by sending a special command to this slave. after performing all necessary initializations of the ssc, the serial interfaces can be enabled. for a master device, the alternate clock line will now go to its programmed polarity. the alternate data line will go to either '0' or '1', until the first transfer will start. when the serial interfaces are enabled, the master device can initiate the first data transfer by writing the transmit data into register ssctb. this value is copied into the shift register (which is assumed to be empty at this time), and the selected first bit of the transmit data will be placed onto the mtsr line on the next clock from the baudrate generator (transmission only starts, if sscen= ? 1 ? ). depending on the selected clock phase, also a clock pulse will be generated on the sclk line. with the opposite clock edge the master at the same time latches and shifts in the data detected at its input line mrst. this ? exchanges ? the transmit data with the receive data. since the clock line is connected to all slaves, their shift registers will be shifted synchronously with the master's shift register, shifting out the data contained in the registers, and shifting in the data detected at the input line. after the preprogrammed number of clock pulses (via the data width selection) the data transmitted by the master is contained in all slaves ? shift registers, while the master's shift register holds the data of the selected slave. in the master and all slaves the content of the shift register is copied into the receive buffer sscrb and the receive interrupt flag sscrir is set.
 3 4#!
#   # 1  user ? s manual 12-9 1999-08  a slave device will immediately output the selected first bit (msb or lsb of the transfer data) at pin mrst, when the content of the transmit buffer is copied into the slave ? s shift register. it will not wait for the next clock from the baudrate generator, as the master does. the reason for this is that, depending on the selected clock phase, the first clock edge generated by the master may be already used to clock in the first data bit. so the slave ? s first data bit must already be valid at this time. note: on the ssc always a transmission and a reception takes place at the same time, regardless whether valid data has been transmitted or received. this is different e.g. from asynchronous reception on asc0. the initialization of the sclk pin on the master requires some attention in order to avoid undesired clock transitions, which may disturb the other receivers. the state of the internal alternate output lines is ? 1 ? as long as the ssc is disabled. this alternate output signal is anded with the respective port line output latch. enabling the ssc with an idle- low clock (sscpo= ? 0 ? ) will drive the alternate data output and (via the and) the port pin sclk immediately low. to avoid this, use the following sequence:  select the clock idle level (sscpo= ? x ? )  load the port output latch with the desired clock idle level (p3.13= ? x ? )  switch the pin to output (dp3.13= ? 1 ? )  enable the ssc (sscen= ? 1 ? )  if sscpo= ? 0 ? : enable alternate data output (p3.13= ? 1 ? ) the same mechanism as for selecting a slave for transmission (separate select lines or special commands) may also be used to move the role of the master to another device in the network. in this case the previous master and the future master (previous slave) will have to toggle their operating mode (sscms) and the direction of their port pins (see description above).
 3 4#!
#   # 1  user ? s manual 12-10 1999-08  12.2 half duplex operation in a half duplex configuration only one data line is necessary for both receiving and transmitting of data. the data exchange line is connected to both pins mtsr and mrst of each device, the clock line is connected to the sclk pin. the master device controls the data transfer by generating the shift clock, while the slave devices receive it. due to the fact that all transmit and receive pins are connected to the one data exchange line, serial data may be moved between arbitrary stations. similar to full duplex mode there are two ways to avoid collisions on the data exchange line:  only the transmitting device may enable its transmit pin driver  the non-transmitting devices use open drain output and only send ones. since the data inputs and outputs are connected together, a transmitting device will clock in its own data at the input pin (mrst for a master device, mtsr for a slave). by these means any corruptions on the common data exchange line are detected, where the received data is not equal to the transmitted data. figure 12-5 ssc half duplex configuration mcs01965 common transmit/ receive line mrst sclk device #2 slave clock shift register mtsr clock master device #1 clock mtsr mrst sclk shift register shift register clock slave device #3 sclk mtsr mrst
 3 4#!
#   # 1  user ? s manual 12-11 1999-08  12.3 continuous transfers when the transmit interrupt request flag is set, it indicates that the transmit buffer ssctb is empty and ready to be loaded with the next transmit data. if ssctb has been reloaded by the time the current transmission is finished, the data is immediately transferred to the shift register and the next transmission will start without any additional delay. on the data line there is no gap between the two successive frames. e.g. two byte transfers would look the same as one word transfer. this feature can be used to interface with devices which can operate with or require more than 16 data bits per transfer. it is just a matter of software, how long a total data frame length can be. this option can also be used e.g. to interface to byte-wide and word-wide devices on the same serial bus. note: of course, this can only happen in multiples of the selected basic data width, since it would require disabling/enabling of the ssc to reprogram the basic data width on-the-fly.
 3 4#!
#   # 1  user ? s manual 12-12 1999-08  12.4 port control the ssc uses three pins of port 3 to communicate with the external world. pin p3.13/ sclk serves as the clock line, while pins p3.8/mrst (master receive / slave transmit) and p3.9/mtsr (master transmit / slave receive) serve as the serial data input/output lines.the operation of these pins depends on the selected operating mode (master or slave). in order to enable the alternate output functions of these pins instead of the general purpose io operation, the respective port latches have to be set to ? 1 ? , since the port latch outputs and the alternate output lines are anded. when an alternate data output line is not used (function disabled), it is held at a high level, allowing io operations via the port latch. the direction of the port lines depends on the operating mode. the ssc will automatically use the correct alternate input or output line of the ports when switching modes. the direction of the pins, however, must be programmed by the user, as shown in the tables. using the open drain output feature helps to avoid bus contention problems and reduces the need for hardwired hand-shaking or slave select lines. in this case it is not always necessary to switch the direction of a port pin. the table below summarizes the required values for the different modes and pins. note: in the table above, an ? x ? means that the actual value is irrelevant in the respective mode, however, it is recommended to set these bits to ? 1 ? , so they are already in the correct state when switching between master and slave mode. ssc port control pin master mode slave mode function port latch direction function port latch direction sclk serial clock output p3.13 = ? 1 ? dp3.13= ? 1 ? serial clock input p3.13 = ? x ? dp3.13= ? 0 ? mtsr serial data output p3.9 = ? 1 ? dp3.9 = ? 1 ? serial data input p3.9 = ? x ? dp3.9 = ? 0 ? mrst serial data input p3.8 = ? x ? dp3.8 = ? 0 ? serial data output p3.8 = ? 1 ? dp3.8 = ? 1 ?
 3 4#!
#   # 1  user ? s manual 12-13 1999-08  12.5 baud rate generation the serial channel ssc has its own dedicated 16-bit baud rate generator with 16-bit reload capability, permitting baud rate generation independent from the timers. the baud rate generator is clocked with the cpu clock divided by 2 ( f cpu /2). the timer is counting downwards and can be started or stopped through the global enable bit sscen in register ssccon. register sscbr is the dual-function baud rate generator/reload register. reading sscbr, while the ssc is enabled, returns the content of the timer. reading sscbr, while the ssc is disabled, returns the programmed reload value. in this mode the desired reload value can be written to sscbr. note: never write to sscbr, while the ssc is enabled. the formulas below calculate either the resulting baud rate for a given reload value, or the required reload value for a given baudrate: represents the content of the reload register, taken as an unsigned 16-bit integer. the table below lists some possible baud rates together with the required reload values and the resulting bit times, for different cpu clock frequencies. table 12-1 ssc baudrate calculations baud rate for f cpu = ... bit time for f cpu = ... reload value (sscbr) 16 mhz 20 mhz 25 mhz 16 mhz 20 mhz 25 mhz reserved. sscbr must be > 0. reserved. sscbr must be > 0. 0000 h 4.00 mbaud 5.00 mbaud 6.25 mbaud 250 ns 200 ns 160 ns 0001 h 2.67 mbaud 3.33 mbaud 4.17 mbaud 375 ns 300 ns 240 ns 0002 h 2.00 mbaud 2.50 mbaud 3.13 mbaud 500 ns 400 ns 320 ns 0003 h 1.60 mbaud 2.00 mbaud 2.50 mbaud 625 ns 500 ns 400 ns 0004 h 1.00 mbaud 1.25 mbaud 1.56 mbaud 1.00 s 800 ns 640 ns 0007 h 800 kbaud 1.0 mbaud 1.25 mbaud 1.25 s1 s 800 ns 0009 h 100 kbaud 125 kbaud 156 kbaud 10 s8 s6.4 s 004f h 80 kbaud 100 kbaud 125 kbaud 12.5 s10 s8 s0063 h 64 kbaud 80 kbaud 100 kbaud 15.6 s12.5 s10 s007c h 1.0 kbaud 1.25 kbaud 1.56 kbaud 1 ms 800 s 640 s1f3f h b ssc = f cpu 2 * ( + 1) sscbr = ( f cpu 2 * baudrate ssc ) - 1
 3 4#!
#   # 1  user ? s manual 12-14 1999-08  12.6 error detection mechanisms the ssc is able to detect four different error conditions. receive error and phase error are detected in all modes, while transmit error and baudrate error only apply to slave mode. when an error is detected, the respective error flag is set. when the corresponding error enable bit is set, also an error interrupt request will be generated by setting ssceir (see figure below). the error interrupt handler may then check the error flags to determine the cause of the error interrupt. the error flags are not reset automatically (like ssceir), but rather must be cleared by software after servicing. this allows servicing of some error conditions via interrupt, while the others may be polled by software. note: the error interrupt handler must clear the associated (enabled) errorflag(s) to prevent repeated interrupt requests. a receive error (master or slave mode) is detected, when a new data frame is completely received, but the previous data was not read out of the receive buffer register sscrb. this condition sets the error flag sscre and, when enabled via sscren, the error interrupt request flag ssceir. the old data in the receive buffer sscrb will be overwritten with the new value and is unretrievably lost. a phase error (master or slave mode) is detected, when the incoming data at pin mrst (master mode) or mtsr (slave mode), sampled with the same frequency as the cpu clock, changes between one sample before and two samples after the latching edge of the clock signal (see ? clock control ? ). this condition sets the error flag sscpe and, when enabled via sscpen, the error interrupt request flag ssceir. a baud rate error (slave mode) is detected, when the incoming clock signal deviates from the programmed baud rate by more than 100%, i.e. it either is more than double or less than half the expected baud rate. this condition sets the error flag sscbe and, when enabled via sscben, the error interrupt request flag ssceir. using this error detection capability requires that the slave's baud rate generator is programmed to the same baud rate as the master device. this feature detects false additional, or missing pulses on the clock line (within a certain frame). 800 baud 1.0 kbaud 1.25 kbaud 1.25 ms 1 ms 800 s270f h 640 baud 800 baud 1.0 kbaud 1.56 ms 1.25 ms 1 ms 30d3 h 122.1 baud 152.6 baud 190.7 baud 8.2 ms 6.6 ms 5.2 ms ffff h table 12-1 ssc baudrate calculations (cont ? d) baud rate for f cpu = ... bit time for f cpu = ... reload value (sscbr) 16 mhz 20 mhz 25 mhz 16 mhz 20 mhz 25 mhz
 3 4#!
#   # 1  user ? s manual 12-15 1999-08  note: if this error condition occurs and bit sscaren= ? 1 ? , an automatic reset of the ssc will be performed in case of this error. this is done to reinitialize the ssc, if too few or too many clock pulses have been detected. a transmit error (slave mode) is detected, when a transfer was initiated by the master (shift clock gets active), but the transmit buffer ssctb of the slave was not updated since the last transfer. this condition sets the error flag sscte and, when enabled via sscten, the error interrupt request flag ssceir. if a transfer starts while the transmit buffer is not updated, the slave will shift out the ? old ? contents of the shift register, which normally is the data received during the last transfer. this may lead to the corruption of the data on the transmit/receive line in half-duplex mode (open drain configuration), if this slave is not selected for transmission. this mode requires that slaves not selected for transmission only shift out ones, i.e. their transmit buffers must be loaded with ? ffff h ? prior to any transfer. note: a slave with push/pull output drivers, which is not selected for transmission, will normally have its output drivers switched. however, in order to avoid possible conflicts or misinterpretations, it is recommended to always load the slave's transmit buffer prior to any transfer. figure 12-6 ssc error interrupt control
 3 4#!
#   # 1  user ? s manual 12-16 1999-08  12.7 ssc interrupt control three bit addressable interrupt control registers are provided for serial channel ssc. register ssctic controls the transmit interrupt, sscric controls the receive interrupt and ssceic controls the error interrupt of serial channel ssc. each interrupt source also has its own dedicated interrupt vector. sctint is the transmit interrupt vector, scrint is the receive interrupt vector, and sceint is the error interrupt vector. the cause of an error interrupt request (receive, phase, baudrate,transmit error) can be identified by the error status flags in control register ssccon. note: in contrary to the error interrupt request flag ssceir, the error status flags sscxe are not reset automatically upon entry into the error interrupt service routine, but must be cleared by software. note: please refer to the general interrupt control register description for an explanation of the control fields. ssctic ssc transmit intr. ctrl. reg. sfr (ff72 h /b9 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ssc tir ssc tie ilvl glvl - - - - - - - - rw rw rw rw sscric ssc receive intr. ctrl. reg. sfr (ff74 h /ba h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ssc rir ssc rie ilvl glvl - - - - - - - - rw rw rw rw ssceic ssc error intr. ctrl. reg. sfr (ff76 h /bb h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ssc eir ssc eie ilvl glvl - - - - - - - - rw rw rw rw
 $ 
 $( user ? s manual 13-1 1999-08  13 the watchdog timer (wdt) to allow recovery from software or hardware failure, the c161pi provides a watchdog timer. if the software fails to service this timer before an overflow occurs, an internal reset sequence will be initiated. this internal reset will also pull the rstout pin low, which also resets the peripheral hardware which might be the cause for the malfunction. when the watchdog timer is enabled and the software has been designed to service it regularly before it overflows, the watchdog timer will supervise the program execution as it only will overflow if the program does not progress properly. the watchdog timer will also time out if a software error was due to hardware related failures. this prevents the controller from malfunctioning for longer than a user-specified time. note: when the bidirectional reset is enabled also pin rstin will be pulled low for the duration of the internal reset sequence upon a software reset or a watchdog timer reset. the watchdog timer provides two registers:  a read-only timer register that contains the current count, and  a control register for initialization and reset source detection. figure 13-1 sfrs and port pins associated with the watchdog timer the watchdog timer is a 16-bit up counter which is clocked with the prescaled cpu clock ( f cpu ). the prescaler divides the cpu clock...  by 2 (wdtin = ? 0 ? ), or  by 128 (wdtin = ? 1 ? ). wdtcon rstout (deactivated by einit) reset indication pins davta registers control registers wdt rstin (bidirectional reset only)
 $ 
 $( user ? s manual 13-2 1999-08  the 16-bit watchdog timer is realized as two concatenated 8-bit timers (see figure below). the upper 8 bits of the watchdog timer can be preset to a user-programmable value via a watchdog service access in order to vary the watchdog expire time. the lower 8 bits are reset upon each service access. figure 13-2 watchdog timer block diagram
 $ 
 $( user ? s manual 13-3 1999-08  13.1 operation of the watchdog timer the current count value of the watchdog timer is contained in the watchdog timer register wdt which is a non-bitaddressable read-only register. the operation of the watchdog timer is controlled by its bitaddressable watchdog timer control register wdtcon. this register specifies the reload value for the high byte of the timer, selects the input clock prescaling factor and also provides flags that indicate the source of a reset. after any reset (except see note) the watchdog timer is enabled and starts counting up from 0000 h with the default frequency f wdt = f cpu /2. the default input frequency may be changed to another frequency ( f wdt = f cpu /128) by programming the prescaler (bit wdtin). the watchdog timer can be disabled by executing the instruction diswdt (disable watchdog timer). instruction diswdt is a protected 32-bit instruction which will only be executed during the time between a reset and execution of either the einit (end of initialization) or the srvwdt (service watchdog timer) instruction. either one of these instructions disables the execution of diswdt. note: after a hardware reset that activates the bootstrap loader the watchdog timer will be disabled. the software reset that terminates the bsl mode will then enable the wdt. when the watchdog timer is not disabled via instruction diswdt it will continue counting up, even during idle mode. if it is not serviced via the instruction srvwdt by the time the count reaches ffff h the watchdog timer will overflow and cause an internal reset. this reset will pull the external reset indication pin rstout low. the watchdog timer reset indication flag (wdtr) in register wdtcon will be set in this case. in bidirectional reset mode also pin rstin will be pulled low for the duration of the internal reset sequence and a long hardware reset will be indicated instead. a watchdog reset will also complete a running external bus cycle before starting the internal reset sequence if this bus cycle does not use ready or samples ready active (low) after the programmed waitstates. otherwise the external bus cycle will be aborted. to prevent the watchdog timer from overflowing it must be serviced periodically by the user software. the watchdog timer is serviced with the instruction srvwdt which is a protected 32-bit instruction. servicing the watchdog timer clears the low byte and reloads the high byte of the watchdog timer register wdt with the preset value from bitfield wdtrel which is the high byte of register wdtcon. servicing the watchdog timer will also reset bit wdtr. after being serviced the watchdog timer continues counting up from the value ( * 2 8 ).
 $ 
 $( user ? s manual 13-4 1999-08  instruction srvwdt has been encoded in such a way that the chance of unintentionally servicing the watchdog timer (e.g. by fetching and executing a bit pattern from a wrong location) is minimized. when instruction srvwdt does not match the format for protected instructions the protection fault trap will be entered, rather than the instruction be executed. note: the reset value depends on the reset source (see description below). the execution of einit clears the reset indication flags. the time period for an overflow of the watchdog timer is programmable in two ways:  the input frequency to the watchdog timer can be selected via a prescaler controlled by bit wdtin in register wdtcon to be f cpu /2 or f cpu /128.  the reload value wdtrel for the high byte of wdt can be programmed in register wdtcon. wdtcon wdt control register sfr (ffae h /d7 h ) reset value: 00xx h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 wdtrel - - - lhw r shw r sw r wdt r wdt in - - - - rh rh rh rh rw bit function wdtin watchdog timer input frequency select controls the input clock prescaler. see table below. wdtr watchdog timer reset indication flag cleared by a hardware reset or by the srvwdt instruction. swr software reset indication flag shwr short hardware reset indication flag lhwr long hardware reset indication flag wdtrel watchdog timer reload value (for the high byte of wdt)
 $ 
 $( user ? s manual 13-5 1999-08  the period p wdt between servicing the watchdog timer and the next overflow can therefore be determined by the following formula: the table below marks the possible ranges (depending on the prescaler bit wdtin) for the watchdog time which can be achieved using a certain cpu clock. note: for safety reasons, the user is advised to rewrite wdtcon each time before the watchdog timer is serviced. table 13-1 watchdog time ranges cpu clock f cpu prescaler reload value in wdtrel wdt in f wdt ff h 7f h 00 h 12 mhz 0 f cpu / 2 42.67 s 5.50 ms 10.92 ms 1 f cpu / 128 2.73 ms 352.3 ms 699.1 ms 16 mhz 0 f cpu / 2 32.00 s 4.13 ms 8.19 ms 1 f cpu / 128 2.05 ms 264.2 ms 524.3 ms 20 mhz 0 f cpu / 2 25.60 s 3.30 ms 6.55 ms 1 f cpu / 128 1.64 ms 211.4 ms 419.4 ms 25 mhz 0 f cpu / 2 20.48 s 2.64 ms 5.24 ms 1 f cpu / 128 1.31 ms 169.1 ms 335.5 ms p wdt = f cpu 2 (1 + *6) * (2 16 - *2 8 )
 $ 
 $( user ? s manual 13-6 1999-08  13.2 reset source indication the reset indication flags in register wdtcon provide information on the source for the last reset. as the c161pi starts executing from location 00 ? 0000 h after any possible reset event the initialization software may check these flags in order to determine if the recent reset event was triggered by an external hardware signal (via rstin ), by software itself or by an overflow of the watchdog timer. the initialization (and also the further operation) of the microcontroller system can thus be adapted to the respective circumstances, e.g. a special routine may verify the software integrity after a watchdog timer reset. the reset indication flags are not mutually exclusive, i.e. more than one flag may be set after reset depending on its source. the table below summarizes the possible combinations: long hardware reset is indicated when the rstin input is still sampled low (active) at the end of a hardware triggered internal reset sequence. short hardware reset is indicated when the rstin input is sampled high (inactive) at the end of a hardware triggered internal reset sequence. software reset is indicated after a reset triggered by the excution of instruction srst. watchdog timer reset is indicated after a reset triggered by an overflow of the watchdog timer. note: when bidirectional reset is enabled the rstin pin is pulled low for the duration of the internal reset sequence upon any sort of reset. therefore always a long hardware reset (lhwr) will be recognized in any case. table 13-2 reset indication flag combinations reset indication flags 1) 1) description of table entries: ? 1 ? = flag is set, ? 0 ? = flag is cleared, ? - ? = flag is not affected, ? * ? = flag is set in bidirectional reset mode, not affected otherwise. event lhwr shwr swr wdtr long hardware reset 1 1 1 0 short hardware reset * 1 1 0 software reset * * 1 - watchdog timer reset * * 1 1 einit instruction 0 0 0 - srvwdt instruction - - - 0
 )  % user ? s manual 14-1 1999-08  14 the real time clock the real time clock (rtc) module of the c161pi basically is an independent timer chain which is clocked directly with the oscillator clock and serves for different purposes:  system clock to determine the current time and date  cyclic time based interrupt  48-bit timer for long term measurements figure 14-1 sfrs associated with the rtc module the rtc module consists of a chain of 3 divider blocks, a fixed 8:1 divider, the reloadable 16-bit timer t14 and the 32-bit rtc timer (accessible via registers rtch and rtcl). both timers count up. the clock signal for the rtc module is directly derived from the on-chip oscillator frequency (not from the cpu clock) and fed through a separate clock driver. it is therefore independent from the selected clock generation mode of the c161pi and is controlled by the clock generation circuitry. note: the rtc registers are not affected by a reset. after a power on reset, however, they are undefined. table 14-1 rtc register location within the esfr space. register name long/short address reset value notes t14 f0d2 h / 69 h uuuu h prescaler timer, generates input clock for rtc register and periodic interrupt t14rel f0d0 h / 68 h uuuu h timer reload register rtch f0d6 h / 6b h uuuu h high word of rtc register rtcl f0d4 h / 6a h uuuu h low word of rtc register syscon2power management control register t14rel timer t14 reload register t14 timer t14 count register t14 e rtch real time clock register, high word rtcl real time clock register, low word isnc interrupt subnode control register xp3ic rtc interrupt control register data registers counter registers interrupt control xp3ic e rtch e isnc e t14rel e rtcl e control registers syscon2e
 )  % user ? s manual 14-2 1999-08  figure 14-2 rtc block diagram system clock operation a real time system clock can be maintained that keeps on running also during idle mode and power down mode (optionally) and represents the current time and date. this is possible as the rtc module is not effected by a reset. the maximum resolution (minimum stepwidth) for this clock information is determined by timer t14 ? s input clock. the maximum usable timespan is achieved when t14rel is loaded with 0000 h and so t14 divides by 2 16 . cyclic interrupt generation the rtc module can generate an interrupt request whenever timer t14 overflows and is reloaded. this interrupt request may e.g. be used to provide a system time tick independent of the cpu frequency without loading the general purpose timers, or to wake up regularly from idle mode. the interrupt cycle time can be adjusted via the timer t14 reload register t14rel. please refer to ? rtc interrupt generation ? below for more details. 48-bit timer operation the concatenation of the 16-bit reload timer t14 and the 32-bit rtc timer can be regarded as a 48-bit timer which is clocked with the rtc input frequency divided by the fixed prescaler. the reload register t14rel should be cleared to get a 48-bit binary timer. however, any other reload value may be used. the maximum usable timespan is 2 48 ( 10 14 ) t14 input clocks, which would equal more than 100 years at an oscillator frequency of 20 mhz. rtcl rtch t14 t14rel 8:1 f rtc reload interrupt request
 )  % user ? s manual 14-3 1999-08  rtc register access the actual value of the rtc is represented by the 3 registers t14, rtcl and rtch. as these registers are concatenated to build the rtc counter chain, internal overflows occur while the rtc is running. when reading or writing the rtc value make sure to account for such internal overflows in order to avoid reading/writing corrupted values. when reading/writing e.g. 0000 h to rtch and then accessing rtcl will produce a corrupted value as rtcl may overflow before it can be accessed. in this case, however, rtch would be 0001 h . the same precautions must be taken for t14 and t14rel. rtc interrupt generation the rtc interrupt shares the xper3 interrupt node with the pll/owd interrupt (if available). this is controlled by the interrupt subnode control register isnc. the interrupt handler can determine the source of an interrupt request via the separate interrupt request and enable flags (see figure below) provided in register isnc. note: if only one source is enabled no additional software check is required, of course. figure 14-3 rtc interrupt logic if t14 interrupts are to be used both stages, the interrupt node (xp3ie= ? 1 ? ) and the rtc subnode (rtcie= ? 1 ? ) must be enabled. please note that the node request bit xp3ir is automatically cleared when the interrupt handler is vectored to, while the subnode request bit rtcir must be cleared by software. pll/owd interrupt intr.request 1) intr.enable 1) pllir pllie intr.request intr.enable rtcir rtcie t14 interrupt xper3 interrupt node interrupt controller note: 1) only available if pll is implemented register xp3ic register isnc
 )  % user ? s manual 14-4 1999-08  defining the rtc time base the reload timer t14 determines the input frequency of the rtc timer, i.e. the rtc time base, as well as the t14 interrupt cycle time. the table below lists the interrupt period range and the t14 reload values (for a time base of 1 s and 1 ms) for several oscillator frequencies: increased rtc accuracy through software correction the accuracy of the c161pi ? s rtc is determined by the oscillator frequency and by the respective prescaling factor (excluding or including t14). the accuracy limit generated by the prescaler is due to the quantization of a binary counter (where the average is zero), while the accuracy limit generated by the oscillator frequency is due to the difference between ideal and real frequency (and therefore accumulates over time). the total accuracy of the rtc can be further increased via software for specific applications that demand a high time accuracy. the key to the improved accuracy is the knowledge of the exact oscillator frequency. the relation of this frequency to the expected ideal frequency is a measure for the rtc ? s deviation. the number n of cycles after which this deviation causes an error of 1 cycle can be easily computed. so the only action is to correct the count by 1 after each series of n cycles. this correction may be applied to the rtc register as well as to t14. also the correction may be done cyclic, e.g. within t14 ? s interrupt service routine, or by evaluating a formula when the rtc registers are read (for this the respective ? last ? rtc value must be available somewhere). note: for the majority of applications, however, the standard accuracy provided by the rtc ? s structure will be more than sufficient. table 14-2 rtc interrupt periods and reload values oscillator frequency rtc interrupt period reload value a reload value b minimum maximum t14rel base t14rel base 32.768khz aux. 244.14 s 16.0 s f000 h 1.000 s fffc h 0.977 ms 32 khz aux. 250 s 16.38 s f060 h 1.000 s fffc h 1.000 ms 32 khz main 8000 s 524.29 s ff83 h 1.000 s ---- ---- 4 mhz main 64.0 s 4.19 s c2f7 h 1.000 s fff0 h 1.024 ms 5 mhz main 51.2 s 3.35 s b3b5 h 0.999 s ffec h 1.024 ms 8 mhz main 32.0 s 2.10 s 85ee h 1.000 s ffe1 h 0.992 ms 10 mhz main 25.6 s 1.68 s 676a h 0.999 s ffd9 h 0.998 ms 12 mhz main 21.3 s 1.40 s 48e5 h 1.000 s ffd2 h 1.003 ms 16 mhz main 16.0 s 1.05 s 0bdc h 1.000 s ffc2 h 0.992 ms
 0 !5 
 user ? s manual 15-1 1999-08  15 the bootstrap loader the built-in bootstrap loader of the c161pi provides a mechanism to load the startup program, which is executed after reset, via the serial interface. in this case no external memory or an internal rom/otp/flash is required for the initialization code starting at location 00 ? 0000 h . the bootstrap loader moves code/data into the internal ram, but it is also possible to transfer data via the serial interface into an external ram using a second level loader routine. rom memory (internal or external) is not necessary. however, it may be used to provide lookup tables or may provide ? core-code ? , i.e. a set of general purpose subroutines, e.g. for io operations, number crunching, system initialization, etc. figure 15-1 bootstrap loader sequence the bootstrap loader may be used to load the complete application software into romless systems, it may load temporary software into complete systems for testing or calibration, it may also be used to load a programming routine for flash devices. the bsl mechanism may be used for standard system startup as well as only for special occasions like system maintenance (firmware update) or end-of-line programming or testing. rstin txd0 int. boot rom bsl-routine 32 bytes 2) 3) rxd0 csp:ip user software 4) 6) p0l.4 1) bsl initialization time, < 70/ f cpu s, ( f cpu in [mhz]). 2) zero byte (1 start bit, eight ? 0 ? data bits, 1 stop bit), sent by host. 3) identification byte, sent by c161pi. 4) 32 bytes of code / data, sent by host. 5) caution: txd0 is only driven a certain time after reception of the zero byte (< 40/ f cpu s, f cpu in [mhz]). 6) internal boot rom. 1) 5)
 0 !5 
 user ? s manual 15-2 1999-08  entering the bootstrap loader the c161pi enters bsl mode if pin p0l.4 is sampled low at the end of a hardware reset. in this case the built-in bootstrap loader is activated independent of the selected bus mode. the bootstrap loader code is stored in a special boot-rom, no part of the standard mask rom, otp or flash memory area is required for this. after entering bsl mode and the respective initialization 1) the c161pi scans the rxd0 line to receive a zero byte, i.e. one start bit, eight ? 0 ? data bits and one stop bit. from the duration of this zero byte it calculates the corresponding baudrate factor with respect to the current cpu clock, initializes the serial interface asc0 accordingly and switches pin txd0 to output. using this baudrate, an identification byte is returned to the host that provides the loaded data. this identification byte identifies the device to be bootet. the following codes are defined: 55 h : 8xc166. a5 h : previous versions of the c167 (obsolete). b5 h : previous versions of the c165. c5 h : c167 derivatives. d5 h : all devices equipped with identification registers. note: the identification byte d5 h does not directly identify a specific derivative. this information can in this case be obtained from the identification registers. when the c161pi has entered bsl mode, the following configuration is automatically set (values that deviate from the normal reset values, are marked ): watchdog timer: disabled register stkun: fa40 h context pointer cp: fa00 h register stkov: fa0c h 0<->c stack pointer sp: fa40 h register buscon0: acc. to startup config. register s0con: 8011 h p3.10 / txd0: ? 1 ? register s0bg: acc. to ? 00 ? byte dp3.10: ? 1 ? other than after a normal reset the watchdog timer is disabled, so the bootstrap loading sequence is not time limited. pin txd0 is configured as output, so the c161pi can return the identification byte. note: even if the internal rom/otp/flash is enabled, no code can be executed out of it. the hardware that activates the bsl during reset may be a simple pull-down resistor on p0l.4 for systems that use this feature upon every hardware reset. you may want to use 1) the external host should not send the zero byte before the end of the bsl initialization time (see figure) to make sure that it is correctly received.
 0 !5 
 user ? s manual 15-3 1999-08  a switchable solution (via jumper or an external signal) for systems that only temporarily use the bootstrap loader. figure 15-2 hardware provisions to activate the bsl after sending the identification byte the asc0 receiver is enabled and is ready to receive the initial 32 bytes from the host. a half duplex connection is therefore sufficient to feed the bsl. note: in order to properly enter bsl mode it is not only required to pull p0l.4 low, but also pins p0l.2, p0l.3, p0l.5 must receive defined levels. this is described in chapter ? system reset ? .
 0 !5 
 user ? s manual 15-4 1999-08  memory configuration after reset the configuration (i.e. the accessibility) of the c161pi ? s memory areas after reset in bootstrap-loader mode differs from the standard case. pin ea is not evaluated when bsl mode is selected, and accesses to the internal code memory are partly redirected, while the c161pi is in bsl mode (see table below). all code fetches are made from the special boot-rom, while data accesses read from the internal code memory. data accesses will return undefined values on romless devices. note: the code in the boot-rom is not an invariant feature of the c161pi. user software should not try to execute code from the internal rom area while the bsl mode is still active, as these fetches will be redirected to the boot-rom. the boot-rom will also ? move ? to segment 1, when the internal rom area is mapped to segment 1. table 15-1 bsl memory configurations 16 mbytes 16 mbytes 16 mbytes bsl mode active yes (p0l.4= ? 0 ? ) yes (p0l.4= ? 0 ? ) no (p0l.4= ? 1 ? ) ea pin high low acc. to application code fetch from internal rom area boot-rom access boot-rom access user rom access data fetch from internal rom area user rom access user rom access user rom access int. rom enabled boot-rom user rom access to external bus disabled access to int. ram 1 0 255 int. rom enabled boot-rom user rom access to external bus enabled access to int. ram 1 0 255 depends on reset config. user rom int. ram 255 1 0 depend s on reset
 0 !5 
 user ? s manual 15-5 1999-08  loading the startup code after sending the identification byte the bsl enters a loop to receive 32 bytes via asc0. these bytes are stored sequentially into locations 00 ? fa40 h through 00 ? fa5f h of the internal ram. so up to 16 instructions may be placed into the ram area. to execute the loaded code the bsl then jumps to location 00 ? fa40 h , i.e. the first loaded instruction. the bootstrap loading sequence is now terminated, the c161pi remains in bsl mode, however. most probably the initially loaded routine will load additional code or data, as an average application is likely to require substantially more than 16 instructions. this second receive loop may directly use the pre-initialized interface asc0 to receive data and store it to arbitrary user-defined locations. this second level of loaded code may be the final application code. it may also be another, more sophisticated, loader routine that adds a transmission protocol to enhance the integrity of the loaded code or data. it may also contain a code sequence to change the system configuration and enable the bus interface to store the received data into external memory. this process may go through several iterations or may directly execute the final application. in all cases the c161pi will still run in bsl mode, i.e. with the watchdog timer disabled and limited access to the internal code memory. all code fetches from the internal rom area (00 ? 0000 h ...00 ? 7fff h or 01 ? 0000 h ...01 ? 7fff h , if mapped to segment 1) are redirected to the special boot-rom. data fetches access will access the internal code memory of the c161pi, if any is available, but will return undefined data on romless devices. exiting bootstrap loader mode in order to execute a program in normal mode, the bsl mode must be terminated first. the c161pi exits bsl mode upon a software reset (ignores the level on p0l.4) or a hardware reset (p0l.4 must be high then!). after a reset the c161pi will start executing from location 00 ? 0000 h of the internal rom or the external memory, as programmed via pin ea .
 0 !5 
 user ? s manual 15-6 1999-08  choosing the baudrate for the bsl the calculation of the serial baudrate for asc0 from the length of the first zero byte that is received, allows the operation of the bootstrap loader of the c161pi with a wide range of baudrates. however, the upper and lower limits have to be kept, in order to insure proper data transfer. the c161pi uses timer t6 to measure the length of the initial zero byte. the quantization uncertainty of this measurement implies the first deviation from the real baudrate, the next deviation is implied by the computation of the s0brl reload value from the timer contents. the formula below shows the association: for a correct data transfer from the host to the c161pi the maximum deviation between the internal initialized baudrate for asc0 and the real baudrate of the host should be below 2.5%. the deviation (f b , in percent) between host baudrate and c161pi baudrate can be calculated via the formula below: note: f unction (f b ) does not consider the tolerances of oscillators and other devices supporting the serial communication. this baudrate deviation is a nonlinear function depending on the cpu clock and the baudrate of the host. the maxima of the function (f b ) increase with the host baudrate due to the smaller baudrate prescaler factors and the implied higher quantization error (see figure below). figure 15-3 baudrate deviation between host and c161pi  cpu 32 s0brl 1 + () ? ------------------------------------------ - b c161pi = s0brl t6 36 ? 72 ------------------ - = t6 9 4 --  cpu b host --------------- ? = , f b b contr b host ? b contr --------------------------------------- - 100 ? = % f b 2,5 % ,
 0 !5 
 user ? s manual 15-7 1999-08  the minimum baudrate (b low in the figure above) is determined by the maximum count capacity of timer t6, when measuring the zero byte, i.e. it depends on the cpu clock. the minimum baudrate is obtained by using the maximum t6 count 2 16 in the baudrate formula. baudrates below b low would cause t6 to overflow. in this case asc0 cannot be initialized properly and the communication with the external host is likely to fail. the maximum baudrate (b high in the figure above) is the highest baudrate where the deviation still does not exceed the limit, i.e. all baudrates between b low and b high are below the deviation limit. b high marks the baudrate up to which communication with the external host will work properly without additional tests or investigations. higher baudrates , however, may be used as long as the actual deviation does not exceed the indicated limit. a certain baudrate (marked i) in the figure) may e.g. violate the deviation limit, while an even higher baudrate (marked ii) in the figure) stays very well below it. any baudrate can be used for the bootstrap loader provided that the following three prerequisites are fulfilled:  the baudrate is within the specified operating range for the asc0  the external host is able to use this baudrate  the computed deviation error is below the limit. table 15-2 bootstrap loader baudrate ranges f cpu [mhz] 10 12 16 20 25 b max 312,500 375,000 500,000 625,000 781,250 b high 9,600 19,200 19,200 19,200 38,400 b stdmin 600 600 600 1,200 1,200 b low 344 412 550 687 859
 0 !5 
 user ? s manual 15-8 1999-08 
c161pi the analog / digital converter user ? s manual 16-1 1999-08 16 the analog / digital converter the c161pi provides an analog / digital converter with 10-bit resolution and a sample & hold circuit on-chip. a multiplexer selects between up to 4 analog input channels (alternate functions of port 5) either via software (fixed channel modes) or automatically (auto scan modes). to fulfill most requirements of embedded control applications the adc supports the following conversion modes:  fixed channel single conversion produces just one result from the selected channel  fixed channel continuous conversion repeatedly converts the selected channel  auto scan single conversion produces one result from each of a selected group of channels  auto scan continuous conversion repeatedly converts the selected group of channels  wait for addat read mode start a conversion automatically when the previous result was read  channel injection mode insert the conversion of a specific channel into a group conversion (auto scan) a set of sfrs and port pins provide access to control functions and results of the adc. figure 16-1 sfrs and port pins associated with the a/d converter adcon a/d converter control register adcic a/d converter interrupt control register (end of conversion) adeic a/d converter interrupt control register (overrun error / channel injection) adcon ports & direction control alternate functions data registers control registers interrupt control addat adcic addat2 e adeic p5 p5 port 5 analog input port : an0/p5.0 ... an3/p5.3 p5didis port 5 digital input disable register addat a/d converter result register addat2 a/d conv. channel injection result reg. p5didis
c161pi the analog / digital converter user ? s manual 16-2 1999-08 the external analog reference voltages v aref and v agnd are fixed. the separate supply for the adc reduces the interference with other digital signals. the conversion time is programmable, so the adc can be adjusted to the internal resistances of the analog sources and/or the analog reference voltage supply. figure 16-2 analog / digital converter block diagram 16.1 mode selection and operation the analog input channels an0...an3 are alternate functions of port 5 which is an input- only port. the port 5 lines may either be used as analog or digital inputs. for pins that shall be used as analog inputs it is recommended to disable the digital input stage via register p5didis. this avoids undesired cross currents and switching noise while the (analog) input signal level is between v il and v ih . the functions of the a/d converter are controlled by the bit-addressable a/d converter control register adcon. its bitfields specify the analog channel to be acted upon, the conversion mode, and also reflect the status of the converter. interrupt requests conversion control adcon 10-bit converter s+h adcir mux adeir an0 : : : an3 result reg. addat v agnd v aref result reg. addat2
c161pi the analog / digital converter user ? s manual 16-3 1999-08 adcon adc control register sfr (ffa0 h /d0 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 adctc adstc ad crq ad cin ad wr ad bsy ad st - adm adch rw rw rwh rw rw rwh rwh - rw rw bit function adch adc analog channel input selection selects the (first) adc channel which is to be converted. note: valid channel numbers are 0 h to 3 h . adm adc mode selection 00: fixed channel single conversion 01: fixed channel continuous conversion 10: auto scan single conversion 11: auto scan continuous conversion adst adc start bit 0: stop a running conversion 1: start conversion(s) adbsy adc busy flag 0: adc is idle 1: a conversion is active. adwr adc wait for read control adcin adc channel injection enable adcrq adc channel injection request flag adstc adc sample time control (defines the adc sample time in a certain range) 00: t bc * 8 01: t bc * 16 10: t bc * 32 11: t bc * 64 adctc adc conversion time control (defines the adc basic conversion clock f bc ) 00: f bc = f cpu / 4 01: f bc = f cpu / 2 10: f bc = f cpu / 16 11: f bc = f cpu / 8
c161pi the analog / digital converter user ? s manual 16-4 1999-08 bitfield adch specifies the analog input channel which is to be converted (first channel of a conversion sequence in auto scan modes). bitfield adm selects the operating mode of the a/d converter. a conversion (or a sequence) is then started by setting bit adst. clearing adst stops the a/d converter after a certain operation which depends on the selected operating mode. the busy flag (read-only) adbsy is set, as long as a conversion is in progress. the result of a conversion is stored in the result register addat, or in register addat2 for an injected conversion. note: bitfield chnr of register addat is loaded by the adc to indicate, which channel the result refers to. bitfield chnr of register addat2 is loaded by the cpu to select the analog channel, which is to be injected. addat adc result register sfr (fea0 h /50 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 chnr - - adres rwh - - rwh addat2 adc chan. inj. result reg. esfr (f0a0 h /50 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 chnr - - adres rw - - rwh bit function adres a/d conversion result the 10-bit digital result of the most recent conversion. chnr channel number (identifies the converted analog channel) note: valid channel numbers are 0 h to 3 h .
c161pi the analog / digital converter user ? s manual 16-5 1999-08 a conversion is started by setting bit adst= ? 1 ? . the busy flag adbsy will be set and the converter then selects and samples the input channel, which is specified by the channel selection field adch in register adcon. the sampled level will then be held internally during the conversion. when the conversion of this channel is complete, the 10-bit result together with the number of the converted channel is transferred into the result register addat and the interrupt request flag adcir is set. the conversion result is placed into bitfield adres of register addat. if bit adst is reset via software, while a conversion is in progress, the a/d converter will stop after the current conversion (fixed channel modes) or after the current conversion sequence (auto scan modes). setting bit adst while a conversion is running, will abort this conversion and start a new conversion with the parameters specified in adcon. note: abortion and restart (see above) are triggered by bit adst changing from ? 0 ? to ? 1 ? , i.e. adst must be ? 0 ? before being set. while a conversion is in progress, the mode selection field adm and the channel selection field adch may be changed. adm will be evaluated after the current conversion. adch will be evaluated after the current conversion (fixed channel modes) or after the current conversion sequence (auto scan modes). fixed channel conversion modes these modes are selected by programming the mode selection bitfield adm in register adcon to ? 00 b ? (single conversion) or to ? 01 b ? (continuous conversion). after starting the converter through bit adst the busy flag adbsy will be set and the channel specified in bit field adch will be converted. after the conversion is complete, the interrupt request flag adcir will be set. in single conversion mode the converter will automatically stop and reset bits adbsy and adst. in continuous conversion mode the converter will automatically start a new conversion of the channel specified in adch. adcir will be set after each completed conversion. when bit adst is reset by software, while a conversion is in progress, the converter will complete the current conversion and then stop and reset bit adbsy.
c161pi the analog / digital converter user ? s manual 16-6 1999-08 auto scan conversion modes these modes are selected by programming the mode selection field adm in register adcon to ? 10 b ? (single conversion) or to ? 11 b ? (continuous conversion). auto scan modes automatically convert a sequence of analog channels, beginning with the channel specified in bit field adch and ending with channel 0, without requiring software to change the channel number. after starting the converter through bit adst, the busy flag adbsy will be set and the channel specified in bit field adch will be converted. after the conversion is complete, the interrupt request flag adcir will be set and the converter will automatically start a new conversion of the next lower channel. adcir will be set after each completed conversion. after conversion of channel 0 the current sequence is complete. in single conversion mode the converter will automatically stop and reset bits adbsy and adst. in continuous conversion mode the converter will automatically start a new sequence beginning with the conversion of the channel specified in adch. when bit adst is reset by software, while a conversion is in progress, the converter will complete the current sequence (including conversion of channel 0) and then stop and reset bit adbsy. figure 16-3 auto scan conversion mode example
c161pi the analog / digital converter user ? s manual 16-7 1999-08 wait for addat read mode if in default mode of the adc a previous conversion result has not been read out of register addat by the time a new conversion is complete, the previous result in register addat is lost because it is overwritten by the new value, and the a/d overrun error interrupt request flag adeir will be set. in order to avoid error interrupts and the loss of conversion results especially when using continuous conversion modes, the adc can be switched to ? wait for addat read mode ? by setting bit adwr in register adcon. if the value in addat has not been read by the time the current conversion is complete, the new result is stored in a temporary buffer and the next conversion is suspended (adst and adbsy will remain set in the meantime, but no end-of-conversion interrupt will be generated). after reading the previous value from addat the temporary buffer is copied into addat (generating an adcir interrupt) and the suspended conversion is started. this mechanism applies to both single and continuous conversion modes. note: while in standard mode continuous conversions are executed at a fixed rate (determined by the conversion time), in ? wait for addat read mode ? there may be delays due to suspended conversions. however, this only affects the conversions, if the cpu (or pec) cannot keep track with the conversion rate. figure 16-4 wait for read mode example
c161pi the analog / digital converter user ? s manual 16-8 1999-08 channel injection mode channel injection mode allows the conversion of a specific analog channel (also while the adc is running in a continuous or auto scan mode) without changing the current operating mode. after the conversion of this specific channel the adc continues with the original operating mode. channel injection mode is enabled by setting bit adcin in register adcon and requires the wait for addat read mode (adwr= ? 1 ? ). the channel to be converted in this mode is specified in bitfield chnr of register addat2. note: bitfield chnr in addat2 is not modified by the a/d converter, but only the adres bit field. since the channel number for an injected conversion is not buffered, bitfield chnr of addat2 must never be modified during the sample phase of an injected conversion, otherwise the input multiplexer will switch to the new channel. it is recommended to only change the channel number with no injected conversion running. figure 16-5 channel injection example a channel injection can be triggered by setting the channel injection request bit adcrq via software.
c161pi the analog / digital converter user ? s manual 16-9 1999-08 after the completion of the current conversion (if any is in progress) the converter will start (inject) the conversion of the specified channel. when the conversion of this channel is complete, the result will be placed into the alternate result register addat2, and a channel injection complete interrupt request will be generated, which uses the interrupt request flag adeir (for this reason the wait for addat read mode is required). note: if the temporary data register used in wait for addat read mode is full, the respective next conversion (standard or injected) will be suspended. the temporary register can hold data for addat (from a standard conversion) or for addat2 (from an injected conversion). figure 16-6 channel injection example with wait for read
c161pi the analog / digital converter user ? s manual 16-10 1999-08 arbitration of conversions conversion requests that are activated while the adc is idle immediately trigger the respective conversion. if a conversion is requested while another conversion is currently in progress the operation of the a/d converter depends on the kind of the involved conversions (standard or injected). note: a conversion request is activated if the respective control bit (adst or adcrq) is toggled from ? 0 ? to ? 1 ? , i.e. the bit must have been zero before being set. the table below summarizes the adc operation in the possible situations. table 16-1 conversion arbitration conversion in progress new requested conversion standard injected standard abort running conversion, and start requested new conversion. complete running conversion, start requested conversion after that. injected complete running conversion, start requested conversion after that. complete running conversion, start requested conversion after that. bit adcrq will be ? 0 ? for the second conversion, however.
c161pi the analog / digital converter user ? s manual 16-11 1999-08 16.2 conversion timing control when a conversion is started, first the capacitances of the converter are loaded via the respective analog input pin to the current analog input voltage. the time to load the capacitances is referred to as sample time. next the sampled voltage is converted to a digital value in successive steps, which correspond to the resolution of the adc. during these phases (except for the sample time) the internal capacitances are repeatedly charged and discharged via pins v aref and v agnd . the current that has to be drawn from the sources for sampling and changing charges depends on the time that each respective step takes, because the capacitors must reach their final voltage level within the given time, at least with a certain approximation. the maximum current, however, that a source can deliver, depends on its internal resistance. the time that the two different actions during conversion take (sampling, and converting) can be programmed within a certain range in the c161pi relative to the cpu clock. the absolute time that is consumed by the different conversion steps therefore is independent from the general speed of the controller. this allows adjusting the a/d converter of the c161pi to the properties of the system: fast conversion can be achieved by programming the respective times to their absolute possible minimum. this is preferable for scanning high frequency signals. the internal resistance of analog source and analog supply must be sufficiently low, however. high internal resistance can be achieved by programming the respective times to a higher value, or the possible maximum. this is preferable when using analog sources and supply with a high internal resistance in order to keep the current as low as possible. the conversion rate in this case may be considerably lower, however. the conversion time is programmed via the upper two bits of register adcon. bitfield adctc (conversion time control) selects the basic conversion clock ( f bc ), used for the operation of the a/d converter. the sample time is derived from this conversion clock. the table below lists the possible combinations. the timings refer to cpu clock cycles, where t cpu = 1 / f cpu . the limit values for f bc (see data sheet) must not be exceeded when selecting adctc and f cpu . table 16-2 adc conversion timing control adcon.15|14 (adctc) a/d converter basic clock f bc adcon.13|12 (adstc) sample time t s 00 f cpu / 4 00 t bc * 8 01 f cpu / 2 01 t bc * 16 10 f cpu / 16 10 t bc * 32 11 f cpu / 8 11 t bc * 64
c161pi the analog / digital converter user ? s manual 16-12 1999-08 the time for a complete conversion includes the sample time t s , the conversion itself and the time required to transfer the digital value to the result register (2 t cpu ) as shown in the example below. note: the non-linear decoding of bit field adctc provides compatibility with 80c166 designs for the default value ( ? 00 ? after reset). converter timing example assumptions: f cpu = 25 mhz (i.e. t cpu = 40 ns), adctc = ? 00 ? , adstc = ? 00 ? . basic clock f bc = f cpu / 4 = 6.25 mhz, i.e. t bc = 160 ns. sample time t s = t bc * 8 = 1280 ns. conversion time t c = t s + 40 t bc + 2 t cpu = (1280 + 6400 + 80) ns = 7.76 ms. note: for the exact specification please refer to the data sheet of the selected derivative.
c161pi the analog / digital converter user ? s manual 16-13 1999-08 16.3 a/d converter interrupt control at the end of each conversion, interrupt request flag adcir in interrupt control register adcic is set. this end-of-conversion interrupt request may cause an interrupt to vector adcint, or it may trigger a pec data transfer which reads the conversion result from register addat e.g. to store it into a table in the internal ram for later evaluation. the interrupt request flag adeir in register adeic will be set either, if a conversion result overwrites a previous value in register addat (error interrupt in standard mode), or if the result of an injected conversion has been stored into addat2 (end-of-injected- conversion interrupt). this interrupt request may be used to cause an interrupt to vector adeint, or it may trigger a pec data transfer. note: please refer to the general interrupt control register description for an explanation of the control fields. adcic adc conversion intr.ctrl.reg. sfr (ff98 h /cc h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - adc ir adc ie ilvl glvl - - - - - - - - rwh rw rw rw adeic adc error intr.ctrl.reg. sfr (ff9a h /cd h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - ade ir ade ie ilvl glvl - - - - - - - - rwh rw rw rw
c161pi the analog / digital converter user ? s manual 16-14 1999-08
 '0 
 user ? s manual 17-1 1999-08  17 the i 2 c bus module the on-chip i 2 c bus module (inter integrated circuit) connects the c161pi to other external controllers and/or peripherals via the two-line serial i 2 c interface. the i 2 c bus module provides communication at data rates of up to 400 kbit/s in master and/or slave mode and features 7-bit addressing as well as 10-bit addressing. note: the i 2 c bus module is an xbus peripheral and therefore requires bit xpen in register syscon to be set in order to be operable. figure 17-1 sfrs associated with the i 2 c bus module the module can operate in three different modes:  master mode , where the c161pi controls the bus transactions and provides the clock signal.  slave mode , where an external master controls the bus transactions and provides the clock signal.  multimaster mode , where several masters can be connected to the bus, i.e. the c161pi can be master or slave. the on-chip i 2 c bus module allows efficient communication over the common i 2 c bus. the module unloads the cpu of the c161pi of low level tasks like  (de)serialization of bus data  generation of start and stop conditions  monitoring the bus lines in slave mode  evaluation of the device address in slave mode  bus access arbitration in multimaster mode sysconsystem configuration register syscon3peripheral management control register xp0ic i 2 c data interrupt control register xp1ic i 2 c protocol interrupt control register icrtb x iccfg i 2 c configuration register iccon i 2 c control register icst i 2 c status register icrtb i 2 c receive transmit buffer icadr i 2 c address register control registers data registers interrupt control xp1ic e icadr x xp0ic e iccfg x core registers syscon iccon x icst x syscon3e
 '0 
 user ? s manual 17-2 1999-08  17.1 i 2 c bus conditions data is transferred over the 2-line i 2 c bus (sda, scl) using a protocol that ensures reliable and efficient transfers. this protocol clearly distinguishes regular data transfers from defined control signals which control the data transfers. the following bus conditions are defined: bus idle : sda and scl remain high. the i 2 c bus is currently not used. data valid : sda stable during the high phase of scl. sda then represents the transferred bit. there is one clock pulse for each transferred bit of data. during data transfers sda may only change while scl is low (see below)! start transfer : a falling edge on sda ( ) while scl is high indicates a start condition. this start condition initiates a data transfer over the i 2 c bus. stop transfer : a rising edge on sda ( ) while scl is high indicates a stop condition. this stop condition terminates a data transfer. between a start condition and a stop condition an arbitrary number of bytes may be transferred.
 '0 
 user ? s manual 17-3 1999-08  the figure below gives examples for these bus conditions. figure 17-2 i 2 c bus conditions the high level of the respective signal is verified. if the signal is low, the previous state (ti) is repeated. the length of each state is 1...256 cpu clock cycles, as defined by bitfield brp in register iccfg (in the above example n=6, i.e. brp=05 h ).
 '0 
 user ? s manual 17-4 1999-08  17.2 the physical i 2 c bus interface communication via the i 2 c bus uses two bidirectional lines, the serial data line sda and the serial clock line scl. these two generic interface lines can each be connected to a number of io port lines of the c161pi (see figure below). these connections can be established and released under software control. figure 17-3 i 2 c bus line connections this mechanism allows a number of configurations of the physical i 2 c bus interface: channel switching: the i 2 c module can be connected to a specific pair of pins (e.g. sda0 and scl0) which then forms a separate i 2 c channel to the external system. the channel can be dynamically switched by connecting the module to another pair of pins (e.g. sda1 and scl1). this establishes physically separate interface channels. broadcasting: connecting the module to more than one pair of pins (e.g. sda0/1 and scl0/1) allows the transmission of messages over multiple physical channels at the same time. please note that this configuration is critical when the c161pi is a slave or receives data. note: never change the physical bus interface configuration while a transfer is in progress. i 2 c module sda0 scl0 sclx sdax generic data line generic clock line
 '0 
 user ? s manual 17-5 1999-08  figure 17-4 physical bus configuration example output pin configuration the pin drivers that are assigned to the i 2 c channel(s) provide open drain outputs (i.e. no upper transistor). this ensures that the i 2 c module does not put any load on the i 2 c bus lines while the c161pi is not powered. the i 2 c bus lines therefore require external pullup resistors (approx. 10 k ? for operation at 100 kbaud, 2 k ? for operation at 400 kbaud). note: if the pins that are assigned to the i 2 c channel(s) are to be used as general purpose io they must be used for open drain outputs or as inputs. all pins of the c161pi that are to be used for i 2 c bus communication must be switched to output and their alternate function must be enabled (by setting the respective port output latch to ? 1 ? ), before any communication can be established. if not driven by the i 2 c module (i.e. the corresponding enable bit in register iccfg is ? 0 ? ) they then switch off their drivers (i.e. driving ? 1 ? to an open drain output). due to the external pullup devices the respective bus levels will then be ? 1 ? which is idle. the i 2 c module features digital input filters in order to improve the rejection of noise from the external bus lines. scl sda i 2 c bus a i 2 c bus node e.g. c161pi scl sda i 2 c bus b i 2 c bus node e.g. c161pi i 2 c bus node e.g. c161pi
 '0 
 user ? s manual 17-6 1999-08  17.3 operating the i 2 c bus the on-chip i 2 c bus module of the c161pi can be operated in variety of operating modes. master or slave operation can be selected, so the i 2 c module can control the external bus (master) or can be controlled via the bus (slave) by a remote master. 7-bit or 10-bit addressing can be selected, so the i 2 c module can communicate with standard 7-bit devices as well as with more sophisticated 10-bit devices. 100 kbd or 400 kbd transfer speed can be selected, so the i 2 c module can communicate with slow devices conforming to the standard i 2 c bus specification as well as with fast devices conforming to the extended specification. physical channels can be selected, so the i 2 c module can use electrically separated channels or increase the addressing range by using more data lines. note: baudrate and physical channels should never be changed (via iccfg) during a transfer. 17.3.1 operation in master mode if the on-chip i 2 c module shall control the i 2 c bus (i.e. be bus master) master mode must be selected via bitfield mod in register iccon. the physical channel is configured by a control word written to register iccfg, defining the active interface pins and the used baudrate. more than one sda and/or scl line may be active at a time. the address of the remote slave that is to be accessed is written to icrtb. the bus is claimed by setting bit bum in register iccon. this generates a start condition on the bus and automatically starts the transmission of the address in icrtb. bit trx in register iccon defines the transfer direction (trx= ? 1 ? , i.e. transmit, for the slave address). a repeated start condition is generated by setting bit rsc in register iccon, which automatically starts the transmission of the address previously written to icrtb. this may be used to change the transfer direction. rsc is cleared automatically after the repeated start condition has been generated. the bus is released by clearing bit bum in register iccon. this generates a stop condition on the bus.
 '0 
 user ? s manual 17-7 1999-08  17.3.2 operation in multimaster mode if multimaster mode is selected via bitfield mod in register iccon the on-chip i 2 c module can operate concurrently as a bus master or as a slave. the descriptions of these modes apply accordingly. multimaster mode implies that several masters are connected to the same bus. as more than one master may try to claim the bus at a given time an arbitration is done on the sda line. when a master device detects a mismatch between the data bit to be sent and the actual level on the sda (bus) line it looses the arbitration and automatically switches to slave mode (leaving the other device as the remaining master). this loss of arbitration is indicated by bit al in register icst which must be checked by the driver software when operating in multimaster mode. lost arbitration is also indicated when the software tries to claim the bus (by setting bit bum) while the i 2 c module is operating in slave mode (indicated by bit bb= ? 1 ? ). bit al must be cleared via software. 17.3.3 operation in slave mode if the on-chip i 2 c module shall be controlled via the i 2 c bus by a remote master (i.e. be a bus slave) slave mode must be selected via bitfield mod in register iccon. the physical channel is configured by a control word written to register iccfg, defining the active interface pins and the used baudrate. it is recommended to have only one sda and scl line active at a time when operating in slave mode. the address by which the slave module can be selected is written to register icadr. the i 2 c module is selected by another master when it receives (after a start condition) either its own device address (stored in icadr) or the general call address (00 h ). in this case an interrupt is generated and bit sla in register icst is set indicating the valid selection. the desired transfer mode is then selected via bit trx (trx= ? 0 ? for reception, trx= ? 1 ? for transmission). for a transmission the respective data byte is placed into the buffer icrtb (which automatically sets bit trx) and the acknowledge behaviour is selected via bit ackdis. for a reception the respective data byte is fetched from the buffer icrtb after irqd has been activated. in both cases the data transfer itself is enabled by clearing bit irqp which releases the scl line. when a stop condition is detected bit sla is cleared. the i 2 c bus configuration register iccfg selects the bus baudrate as well as the activation of sda and scl lines. so an external i 2 c channel can be established (baudrate and physical lines) with one single register access.
 '0 
 user ? s manual 17-8 1999-08  systems that utilize several i 2 c channels can prepare a set of control words which configure the respective channels. by writing one of these control words to iccfg the respective channel is selected. different channels may use different baudrates. also different operating modes can be selected, e.g. enabling all physical interfaces for a broadcast transmission. note: see also section ? the physical i 2 c bus interface ? . iccfg i 2 c configuration reg. xreg (ed00 h ) reset value: xx00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 brp - - scl sel 1 scl sel 0 - sda sel 2 sda sel 1 sda sel 0 rw - - rw rw - rw rw rw bit function sdaselx sda pin selection these bits determine to which pins the i 2 c data line is connected. 0: sda pin x is disconnected. 1: sda pin x is connected with i 2 c data line. sclselx scl pin selection these bits determine to which pins the i 2 c clock line is connected. 0: scl pin x is disconnected. 1: scl pin x is connected with i 2 c clock line. brp baudrate prescaler determines the baudrate for the active i 2 c channel(s). the resulting baudrate is b i2c = f cpu / (4 * (brp+1)). see table below. table 17-1 i 2 c bus baudrate selection cpu frequency f cpu reload value for brp 100 kbd 400 kbd 20 mhz 31 h 0b h or 0c h 16 mhz 27 h 09 h 12 mhz 1d h 06 h or 07 h 10 mhz 18 h 05 h 1 mhz 01 h or 02 h not possible.
 '0 
 user ? s manual 17-9 1999-08  iccon i 2 c control reg. xreg (ed02 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 --------trx air dis ack dis bum mod rsc m10 - - - - - - - - rwh rw rw rwh rw rwh rw bit function m10 address mode 0: 7-bit addressing using ica.7-1. 1: 10-bit addressing using ica.9-0. rsc repeated start condition 0: no operation. rsc is cleared automatically after the repeated start condition has been sent. 1: generate a repeated start condition in (multi)master mode. rsc cannot be set in slave mode. mod basic operating mode 00: i 2 c module is disabled and initialized. 01: slave mode. 10: master mode. 11: multi-master mode. bum busy master 0: clearing bit bum ( ) generates a stop condition. 1: setting bit bum generates a start condition in (multi)master mode. setting bum ( ) while bb= ? 1 ? generates an arbitration lost situation. in this case bum is cleared and bit al is set. bum cannot be set in slave mode. ackdis acknowledge pulse disable 0: an acknowledge pulse is generated for each received frame. 1: no acknowledge pulse is generated. airdis auto interrupt reset disable 0: irqd is cleared automatically upon a read/write access to icrtb. (advantageous if data are read/written via pec transfers) 1: irqd must explicitly be cleared via software. (allows to trigger a stop condition after the last data transfer before the bus is released by clearing irqd.) trx transmit select 0: data is received from the i 2 c bus. 1: data is transmitted to the i 2 c bus. trx is set automatically when writing to the transmit buffer icrtb.
 '0 
 user ? s manual 17-10 1999-08  the i 2 c address register icadr stores the device address (ica) which identifies the i 2 c node when operating in slave mode. bit m10 in register iccon determines which part of icadr is valid and used. the i 2 c receive/transmit buffer (icrtb) accepts bytes to be transmitted and provides received bytes. note: it is recommended not to access the receive/transmit buffer while a data transfer is in progress. icadr i 2 c address reg. xreg (ed06 h ) reset value: 0xxx h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------ica.9...8 ica.7...1 ica. 0 - - - - - - rw rw rw bit function ica.7-1 address in 7-bit mode (ica.9, ica.8, ica.0 disregarded). ica.0-9 address in 10-bit mode (all bits used). icrtb i 2 c receive/transmit buffer xreg (ed08 h ) reset value: - - xx h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - reserved - icdata - - - - - - - - rw bit function icdata transmit and shift data this field accepts the byte to be transmitted or provides the received byte. note: a data transfer event interrupt request (irqd) is cleared automatically when reading from or writing to icrtb, if bit airdis= ? 0 ? . if airdis= ? 1 ? the request flag irqd must be cleared via software.
 '0 
 user ? s manual 17-11 1999-08  icst i 2 c status reg. xreg (ed04 h ) reset value: 000x h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ---------irqpirqdbblrbslaaladr - - - - - - - - - rwh rwh rh rh rh rwh rh bit function adr address bit adr is set after a start condition in slave mode until the address has been received (1 byte in 7-bit address mode, 2 bytes in 10-bit address mode). al arbitration lost bit al is set when the i 2 c module has tried to become master on the bus but has lost the arbitration. operation is continued until the 9th clock pulse. bit irqp is set along with bit al. bit al must be cleared via software. sla slave 0: the i 2 c bus is not busy, or the module is in master mode. 1: the i 2 c module has been selected as a slave (device addr. received). lrb last received bit (undefined after reset) bit lrb represents the last bit (i.e. the acknowledge bit) of the last transmitted or received frame. bb bus busy 0: the i 2 c bus is idle, i.e. a stop condition has occurred. 1: the i 2 c bus is active, i.e. a start condition has occurred. bit bb is always ? 0 ? while the i 2 c module is disabled. irqd i 2 c interrupt request bit for data transfer events 1) 0: no interrupt request pending. 1: a data transfer event interrupt request is pending. irqd is set after the acknowledge bit of a byte has been received or transmitted, and is cleared automatically upon a read or write access to the buffer icrtb if bit airdis= ? 0 ? . irqd must be cleared via software if bit airdis= ? 1 ? . irqp i 2 c interrupt request bit for protocol events 1) 0: no interrupt request pending. 1: a protocol event interrupt request is pending. irqp is set when bit sla or bit al is set ( ), and must be cleared via software.
 '0 
 user ? s manual 17-12 1999-08  17.4 i 2 c interrupt control the bit addressable interrupt control registers xp0ic and xp1ic are assigned to the i 2 c module. the occurrence of an interrupt request sets the respective interrupt request bit xp0ir/xp1ir. if this interrupt node is enabled (xpxen= ? 1 ? ) a cpu interrupt is generated and arbitrated. these interrupt requests may be serviced via a standard service routine or with pec transfers (see below). if polling of bits xp0ir and xp1ir is used please note that these request bits must be cleared via software. data transfer event interrupts are indicated by bit irqd and allocated to vector xp0int . a data transfer event occurs after the acknowledge bit for a byte has been received or transmitted. protocol transfer event interrupts are indicated by bit irqp and allocated to vector xp1int . a protocol transfer event occurs when bit sla is set, i.e. a slave address is received, or when bit al is set, i.e. the bus arbitration has been lost. as long as either interrupt request flag (irqd or irqp) of the i 2 c bus module is set the selected clock line(s) sclx is/are held low. this disables any further transfer on the i 2 c bus and enables the driver software to react on the recent event. when both request bits are cleared the clock line(s) is/are released again and subsequent bus transfers can take place. note: the interrupt node request bits xp0ir and xp1ir are cleared automatically when the cpu services the respective interrupt (not in case of polling!). the i 2 c bus module interrupt request bit irqp must be cleared via the driver software. the i 2 c bus module interrupt request bit irqd is cleared automatically upon a read/write access to buffer icrtb if bit airdis= ? 0 ? , otherwise it must be cleared via the driver software. 1) while either irqd or irqp is set and the i 2 c module is in master mode or has been selected as a slave, the i 2 c clock line is held low which prevents further transfers on the i 2 c bus. the clock line (i.e. the i 2 c bus) is released when both irqd and irqp are cleared. only in this case the next i 2 c bus action can take place. note that irqd is cleared automatically upon a read or write access to register icrtb if bit airdis is not set. both interrupt request bits may be set or cleared via software, e.g. to control the i 2 c bus.
 '0 
 user ? s manual 17-13 1999-08  note: please refer to the general interrupt control register description for an explanation of the control fields. xp0ic i 2 c data intr. ctrl. reg. esfr (f186 h /c3 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - xp0 ir xp0 ie ilvl glvl -------- rwh rw rw rw xp1ic i 2 c protocol intr. ctrl. reg. esfr (f18e h /c7 h ) reset value: - - 00 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - xp1 ir xp1 ie ilvl glvl -------- rwh rw rw rw
 '0 
 user ? s manual 17-14 1999-08  17.5 programming example the sample program below illustrates an i 2 c communication between the c161pi and an nvram (such as sda2526 or sla24c04). it uses 7-bit addressing with a slave address of 50 h which is concatenated with the read/write bit. this program does not use interrupts, but polls the corresponding i 2 c interrupt request flags. the master (c161pi) starts in master transmitter mode and first sends the slave address (a0 h = 50 h //0 b ) followed by the subaddress (00 h ) . the c161pi changes to master receiver mode, repeats the slave address (a1 h = 50 h //1 b ) and then receives two bytes. the first byte is acknowledged (ack= ? 0 ? ) by the master, the second byte is not acknowledged (ack= ? 1 ? ). the transfer is finished with a stop condition by the master. the following figure shows the waveforms for the described transfer. a programming example in ? c ? illustrates how the operation could be realized. figure 17-5 i 2 c bus programming example waveforms legend: sda: data line scl: clock line st: start condition sp: stop condition rs: repeated start cond. ack: acknow- ledge nack: no acknow.
 '0 
 user ? s manual 17-15 1999-08  /*---------------------------------------------------------------*\ | programming example to read 2 bytes from an nvram | | via the i2c bus. | \*---------------------------------------------------------------*/ void main() { // x-peripheral enable: syscon |= 0x0004; // set xpen, before einit-instr.!!! // i2c control register configuration: iccon = 0x0008; // master mode icst = 0x0000; // reset status register iccfg = 0x2711; // 100khz @ 16mhz, sda0, scl0 xp0ic = 0x0000; // disable interrupt irqd, use polling xp1ic = 0x0000; // disable interrupt irqp, use polling // port configuration (provide external pullups on i2c-lines!): // (the actual physical port depends on the respective device! // the i2c interface e.g. uses p3 on the c161ri, p9 on the c161si/ci) _bfld_ ( p*, 0x0003, 0x0003); // enable alternate function on p*.0-1 _bfld_ (dp*, 0x0003, 0x0003); // switch i2c pins to output // slave address icrtb = 0x0000 | 0xa0; // write transmit buffer iccon |= bum; // bum=1: start cond. + send slave addr. while((icst & irqd) == 0x0000); // waiting for end of transmission if (icst & lrb) // ack? { icst &= ~al; // clear bit al icst &= ~irqp; // clear bit irqp } // sub address icrtb = 0x0000|0x0000; // send sub-address while((icst & irqd)== 0x0000); // waiting for end of transmission if (icst & lrb) // ack? { icst &= ~al; // clear bit al icst &= ~irqp; // clear bit irqp }
 '0 
 user ? s manual 17-16 1999-08  // switch to master-receiver, send slave address with a repeated start: iccon |= rsc; // repeated start condition icrtb = 0x0000|0xa1; // write to transmit buffer while((icst & irqd)== 0x0000); // waiting for end of transmission if (icst & lrb) // ack? { icst &= ~al; // clear bit al icst &= ~irqp; // clear bit irqp } // drive clock (scl) for first byte, give ack: iccon &= ~ackdis; // acknowledge from master iccon &= ~trx; // trx = 0 for master receiver dummy = icrtb; // start clock to receive the 1st byte while((icst & irqd)==0x0000); // waiting for end of 1st byte // read first byte, drive clock for second, give no ack: iccon |= ackdis; // no acknowledge from master array[0] = icrtb; // read icrtb (1st byte), // start clock to receive the 2nd byte while((icst & irqd)==0x0000); // waiting for end of 2nd byte // read 2nd byte without automatic clear of irqd, generate stop: iccon |= airdis; // airdis=1: read icrtb, send no clock array[1] = icrtb; // read icrtb (2nd byte) iccon &= ~bum; // bum=0: initiate stop condition icst &= ~irqd; // clear bit irqd }
 #) user ? s manual 18-1 1999-08  18 system reset the internal system reset function provides initialization of the c161pi into a defined default state and is invoked either by asserting a hardware reset signal on pin rstin (hardware reset input), upon the execution of the srst instruction (software reset) or by an overflow of the watchdog timer. whenever one of these conditions occurs, the microcontroller is reset into its predefined default state through an internal reset procedure. when a reset is initiated, pending internal hold states are cancelled and the current internal access cycle (if any) is completed. an external bus cycle is aborted, except for a watchdog reset (see description). after that the bus pin drivers and the io pin drivers are switched off (tristate). the internal reset procedure requires 516 cpu clock cycles in order to perform a complete reset sequence. this 516 cycle reset sequence is started upon a watchdog timer overflow, a srst instruction or when the reset input signal rstin is latched low (hardware reset). the internal reset condition is active at least for the duration of the reset sequence and then until the rstin input is inactive and the pll has locked (if the pll is selected for the basic clock generation). when this internal reset condition is removed (reset sequence complete, rstin inactive, pll locked) the reset configuration is latched from port0, rd . after that pins ale, rd , and wr are driven to their inactive levels. note: bit adp which selects the adapt mode is latched with the rising edge of rstin . after the internal reset condition is removed, the microcontroller will start program execution from memory location 00 ? 0000 h in code segment zero. this start location will typically hold a branch instruction to the start of a software initialization routine for the application specific configuration of peripherals and cpu special function registers. figure 18-1 external reset circuitry c161pi rstin
 #) user ? s manual 18-2 1999-08  18.1 reset sources several sources (external or internal) can generate a reset for the c161pi. software can identify the respective reset source via the reset source indication flags in register wdtcon. generally any reset causes the same actions on the c161pi ? s modules. the differences are described in the following sections. hardware reset a hardware reset is triggered when the reset input signal rstin is latched low. to ensure the recognition of the rstin signal (latching), it must be held low for at least 100 ns plus 2 cpu clock cycles (input filter plus synchronization). also shorter rstin pulses may trigger a hardware reset, if they coincide with the latch ? s sample point. the actual minimum duration for a reset pulse depends on the current cpu clock generation mode. the worstcase is generating the cpu clock via the slowdown divider using the maximum factor while the configured basic mode uses the prescaler ( f cpu = f osc / 64 in this case). after the reset sequence has been completed, the rstin input is sampled again. when the reset input signal is inactive at that time, the internal reset condition is terminated (indicated as short hardware reset, shwr). when the reset input signal is still active at that time, the internal reset condition is prolonged until rstin gets inactive (indicated as long hardware reset, lhwr). during a hardware reset the inputs for the reset configuration (port0, rd ) need some time to settle on the required levels, especially if the hardware reset aborts a read operation from an external peripheral. during this settling time the configuration may intermittently be wrong. for the duration of one internal reset sequence after a reset has been recognized the configuration latches are not transparent, i.e. the (new) configuration becomes valid earliest after the completion of one reset sequence. this usually covers the required settling time. when the basic clock is generated by the pll the internal reset condition is automatically extended until the on-chip pll has locked. the input rstin provides an internal pullup device equalling a resistor of 50 k ? to 150 k ? (the minimum reset time must be determined by the lowest value). simply connecting an external capacitor is sufficient for an automatic power-on reset (see b) in figure above). rstin may also be connected to the output of other logic gates (see a) in figure above). see also section ? bidirectional reset ? in this case. note: a power-on reset requires an active time of two reset sequences (1036 cpu clock cycles) after a stable clock signal is available (about 10...50 ms, depending on the oscillator frequency, to allow the on-chip oscillator to stabilize).
 #) user ? s manual 18-3 1999-08  software reset the reset sequence can be triggered at any time via the protected instruction srst (software reset). this instruction can be executed deliberately within a program, e.g. to leave bootstrap loader mode, or upon a hardware trap that reveals a system failure. note: a software reset only latches the configuration of the bus interface (salsel, cssel, wrc, bustyp) from port0. if bidirectional reset is enabled, a software reset is executed like a long hardware reset. watchdog timer reset when the watchdog timer is not disabled during the initialization or serviced regularly during program execution it will overflow and trigger the reset sequence. other than hardware and software reset the watchdog reset completes a running external bus cycle if this bus cycle either does not use ready at all, or if ready is sampled active (low) after the programmed waitstates. when ready is sampled inactive (high) after the programmed waitstates the running external bus cycle is aborted. then the internal reset sequence is started. note: a watchdog reset only latches the configuration of the bus interface (salsel, cssel, wrc, bustyp) from port0. if bidirectional reset is enabled a watchdog timer reset is executed like a long hardware reset. the watchdog reset cannot occur while the c161pi is in bootstrap loader mode!
 #) user ? s manual 18-4 1999-08  bidirectional reset in a special mode (bidirectional reset) the c161pi ? s line rstin (normally an input) may be driven active by the chip logic e.g. in order to support external equipment which is required for startup (e.g. flash memory). figure 18-2 bidirectional reset operation bidirectional reset reflects internal reset sources (software, watchdog) also to the rstin pin and converts short hardware reset pulses to a minimum duration of the internal reset sequence. bidirectional reset is enabled by setting bit bdrsten in register syscon and changes rstin from a pure input to an open drain io line. when an internal reset is triggered by the srst instruction or by a watchdog timer overflow or a low level is applied to the rstin line, an internal driver pulls it low for the duration of the internal reset sequence. after that it is released and is then controlled by the external circuitry alone. the bidirectional reset function is useful in applications where external devices require a defined reset signal but cannot be connected to the c161pi ? s rstout signal, e.g. an external flash memory which must come out of reset and deliver code well before rstout can be deactivated via einit. the following behaviour differences must be observed when using the bidirectional reset feature in an application:  bit bdrsten in register syscon cannot be changed after einit.  after a reset bit bdrsten is cleared.  the reset indication flags always indicate a long hardware reset.  the port0 configuration is treated like on a hardware reset. especially the bootstrap loader may be activated when p0l.4 is low.  pin rstin may only be connected to ext. reset devices with an open drain output driver.  a short hardware reset is extended to the duration of the internal reset sequence. internal circuitry rstin & reset sequence active bdrsten = ? 1 ?
 #) user ? s manual 18-5 1999-08  18.2 status after reset after a reset is completed most units of the c161pi enter a well-defined default status. this ensures repeatable start conditions and avoids spurious activities after reset. watchdog timer operation after reset the watchdog timer starts running after the internal reset has completed. it will be clocked with the internal system clock divided by 2 ( f cpu / 2), and its default reload value is 00 h , so a watchdog timer overflow will occur 131,072 cpu clock cycles (2 * 2 16 ) after completion of the internal reset, unless it is disabled, serviced or reprogrammed meanwhile. when the system reset was caused by a watchdog timer overflow, the wdtr (watchdog timer reset indication) flag in register wdtcon will be set to ? 1 ? . this indicates the cause of the internal reset to the software initialization routine. wdtr is reset to ? 0 ? by an external hardware reset, by servicing the watchdog timer or after einit. after the internal reset has completed, the operation of the watchdog timer can be disabled by the diswdt (disable watchdog timer) instruction. this instruction has been implemented as a protected instruction. for further security, its execution is only enabled in the time period after a reset until either the srvwdt (service watchdog timer) or the einit instruction has been executed. thereafter the diswdt instruction will have no effect. reset values for the c161pi registers during the reset sequence the registers of the c161pi are preset with a default value. most sfrs, including system registers and peripheral control and data registers, are cleared to zero, so all peripherals and the interrupt system are off or idle after reset. a few exceptions to this rule provide a first pre-initialization, which is either fixed or controlled by input pins. dpp1: 0001 h (points to data page 1) dpp2: 0002 h (points to data page 2) dpp3: 0003 h (points to data page 3) cp: fc00 h stkun: fc00 h stkov: fa00 h sp: fc00 h wdtcon: 00xx h (value depends on the reset source) s0rbuf: xx h (undefined) sscrb: xxxx h (undefined) syscon: 0xx0 h (set according to reset configuration) buscon0: 0xx0 h (set according to reset configuration) rp0h: xx h (reset levels of p0h) ones: ffff h (fixed value)
 #) user ? s manual 18-6 1999-08  the c161pi ? s pins after reset after the reset sequence the different groups of pins of the c161pi are activated in different ways depending on their function. bus and control signals are activated immediately after the reset sequence according to the configuration latched from port0, so either external accesses can takes place or the external control signals are inactive. the general purpose io pins remain in input mode (high impedance) until reprogrammed via software (see figure below). the rstout pin remains active (low) until the end of the initialization routine (see description). figure 18-3 reset input and output signals 1) current bus cycle is completed or aborted. 2) switches asynchronously with rstin , synchronously upon software or watchdog reset. 3) the reset condition ends here. the c161pi starts program execution. 4) activation of the io pins is controlled by software. 5) execution of the einit instruction. 6) the shaded area designates the internal reset sequence, which starts after synchronization of rstin . 7) a short hardware reset is extended until the end of the reset sequence in bidirectional reset mode. 8) a software or wdt reset activates the rstin line in bidirectional reset mode. when the internal reset condition is extended by rstin , the activation of the output signals is delayed until the end of the internal reset condition. 7) 8)
 #) user ? s manual 18-7 1999-08  ports and external bus configuration during reset during the internal reset sequence all of the c161pi ? s port pins are configured as inputs by clearing the associated direction registers, and their pin drivers are switched to the high impedance state. this ensures that the c161pi and external devices will not try to drive the same pin to different levels. pin ale is held low through an internal pulldown, and pins rd , wr and ready are held high through internal pullups. also the pins that can be configured for cs output will be pulled high. the registers syscon and buscon0 are initialized according to the configuration selected via port0. when an external start is selected (pin ea = ? 0 ? ):  the bus type field (btyp) in register buscon0 is initialized according to p0l.7 and p0l.6  bit busact0 in register buscon0 is set to ? 1 ?  bit alectl0 in register buscon0 is set to ? 1 ?  bit romen in register syscon will be cleared to ? 0 ?  bit bytdis in register syscon is set according to the data bus width (set if 8-bit)  bit wrcfg in register syscon is set according to pin p0h.0 (wrc) when an internal start is selected (pin ea = ? 1 ? ):  register buscon0 is cleared to 0000 h  bit romen in register syscon will be set to ? 1 ?  bit bytdis in register syscon is set, i.e. bhe /wrh is disabled  bit wrcfg in register syscon is set according to pin p0h.0 (wrc) the other bits of register buscon0, and the other buscon registers are cleared. this default initialization selects the slowest possible external accesses using the configured bus type. when the internal reset has completed, the configuration of port0, port1, port 4 port 6 and of the bhe signal (high byte enable, alternate function of p3.12) depends on the bus type which was selected during reset. when any of the external bus modes was selected during reset, port0 will operate in the selected bus mode. port 4 will output the selected number of segment address lines (all zero after reset) and port 6 will drive the selected number of cs lines (cs0 will be ? 0 ? , while the other active cs lines will be ? 1 ? ). when no memory accesses above 64 k are to be performed, segmentation may be disabled. when the on-chip bootstrap loader was activated during reset, pin txd0 (alternate port function) will be switched to output mode after the reception of the zero byte. all other pins remain in the high-impedance state until they are changed by software or peripheral operation.
 #) user ? s manual 18-8 1999-08  reset output pin the rstout pin is dedicated to generate a reset signal for the system components besides the controller itself. rstout will be driven active (low) at the begin of any reset sequence (triggered by hardware, the srst instruction or a watchdog timer overflow). rstout stays active (low) beyond the end of the internal reset sequence until the protected einit (end of initialization) instruction is executed (see figure above). this allows the complete configuration of the controller including its on-chip peripheral units before releasing the reset signal for the external peripherals of the system. note: rstout will float as long as pins p0l.0 and p0l.1 select emulation mode or adapt mode. the internal ram after reset the contents of the internal ram are not affected by a system reset. however, after a power-on reset, the contents of the internal ram are undefined. this implies that the gprs (r15...r0) and the pec source and destination pointers (srcp7...srcp0, dstp7...dstp0) which are mapped into the internal ram are also unchanged after a warm reset, software reset or watchdog reset, but are undefined after a power-on reset. the extension ram (xram) after reset the contents of the on-chip extension ram are not affected by a system reset. however, after a power-on reset, the contents of the xram are undefined. operation after reset after the internal reset condition is removed the c161pi fetches the first instruction from the program memory (location 00 ? 0000 h for a standard start). as a rule, this first location holds a branch instruction to the actual initialization routine that may be located anywhere in the address space. note: when the bootstrap loader mode was activated during a hardware reset the c161pi does not fetch instructions from the program memory. the standard bootstrap loader expects data via serial interface asc0.
 #) user ? s manual 18-9 1999-08  18.3 application-specific initialization routine after a reset the modules of the c161pi must be initialized to enable their operation on a given application. this initialization depends on the task the c161pi is to fulfill in that application and on some system properties like operating frequency, connected external circuitry, etc. the following initializations should typically be done, before the c161pi is prepared to run the actual application software: memory areas the external bus interface can be reconfigured after an external reset because register buscon0 is initialized to the slowest possible bus cycle configuration. the programmable address windows can be enabled in order to adapt the bus cycle characteristics to different memory areas or peripherals. also after a single-chip mode reset the external bus interface can be enabled and configured. the internal program memory (if available) can be enabled and mapped after an external reset in order to use the on-chip resources. after a single-chip mode reset the internal program memory can be remapped or disabled at all in order to utilize external memory (partly or completely). programmable program memory can be programmed, e.g. with data received over a serial link. note: initial flash or otp programming will rather be done in bootstrap loader mode. system stack the deafult setup for the system stack (size, stackpointer, upper and lower limit registers) can be adjusted to application-specific values. after reset, registers sp and stkun contain the same reset value 00 ? fc00 h , while register stkov contains 00 ? fa00 h . with the default reset initialization, 256 words of system stack are available, where the system stack selected by the sp grows downwards from 00 ? fbfe h . note: the interrupt system, which is disabled upon completion of the internal reset, should remain disabled until the sp is initialized. traps (incl. nmi ) may occur, even though the interrupt system is still disabled. register bank the location of a register bank is defined by the context pointer (cp) and can be adjusted to an application-specific bank before the general purpose registers (gprs) are used. after reset, register cp contains the value 00 ? fc00 h , i.e. the register bank selected by the cp grows upwards from 00 ? fc00 h .
 #) user ? s manual 18-10 1999-08  on-chip ram based on the application, the user may wish to initialize portions of the internal writable memory (iram/xram) before normal program operation. once the register bank has been selected by programming the cp register, the desired portions of the internal memory can easily be initialized via indirect addressing. interrupt system after reset the individual interrupt nodes and the global interrupt system are disabled. in order to enable interrupt requests the nodes must be assigned to their respective interrupt priority levels and be enabled. the vector locations must receive pointers to the respective exception handlers. the interrupt system must globally be enabled by setting bit ien in register psw. care must be taken not to enable the interrupt system before the initialization is complete in order to avoid e.g. the corruption of internal memory locations by stack operations using an uninitialized stack pointer. watchdog timer after reset the watchdog timer is active and is counting its default period. if the watchdog timer shall remain active the desired period should be programmed by selecting the appropriate prescaler value and reload value. otherwise the watchdog timer must be disabled before einit. ports generally all ports of the c161pi are switched to input after reset. some pins may be automatically controlled, e.g. bus interface pins for an external start, txd in boot mode, etc. pins that shall be used for general purpose io must be initialized via software. the required mode (input/output, open drain/push pull, input threshold, etc.) depends on the intended function for a given pin. peripherals after reset the c161pi ? s on-chip peripheral modules enter a defined default state (see respective peripheral description) where it is disabled from operation. in order to use a certain peripheral it must be initialized according to its intended operation in the application. this includes selecting the operating mode (e.g. counter/timer), operating parameters (e.g. baudrate), enabling interface pins (if required), assigning interrupt nodes to the respective priority levels, etc. after these standard initialization also application-specific actions may be required like asserting certain levels to output pins, sending codes via interfaces, latching input levels, etc.
 #) user ? s manual 18-11 1999-08  termination of initialization the software initialization routine should be terminated with the einit instruction. this instruction has been implemented as a protected instruction. the execution of the einit instruction...  disables the action of the diswdt instruction,  disables write accesses to reg. syscon (all configurations regarding reg. syscon (enable clkout, stacksize, etc.) must be selected before the execution of einit),  disables write accesses to registers syscon2 and syscon3 (further write accesses to syscon2 and syscon3 can be executed only using a special unlock mechanism),  clears the reset source detection bits in register wdtcon,  causes the rstout pin to go high (this signal can be used to indicate the end of the initialization routine and the proper operation of the microcontroller to external hardware).
 #) user ? s manual 18-12 1999-08  18.4 system startup configuration although most of the programmable features of the c161pi are selected by software either during the initialization phase or repeatedly during program execution, there are some features that must be selected earlier, because they are used for the first access of the program execution (e.g. internal or external start selected via ea ). these configurations are accomplished by latching the logic levels at a number of pins at the end of the internal reset sequence. during reset internal pullup/pulldown devices are active on those lines. they ensure inactive/default levels at pins which are not driven externally. external pulldown/pullup devices may override the default levels in order to select a specific configuration. many configurations can therefore be coded with a minimum of external circuitry. note: the load on those pins that shall be latched for configuration must be small enough for the internal pullup/pulldown device to sustain the default level, or external pullup/pulldown devices must ensure this level. those pins whose default level shall be overridden must be pulled low/high externally. make sure that the valid target levels are reached until the end of the reset sequence. there is a specific application note to illustrate this.
 #) user ? s manual 18-13 1999-08  18.4.1 system startup configuration upon an external reset for an external reset (ea = ? 0 ? ) the startup configuration uses the pins of port0 and pin rd . the value on the upper byte of port0 (p0h) is latched into register rp0h upon reset, the value on the lower byte (p0l) directly influences the buscon0 register (bus mode) or the internal control logic of the c161pi. figure 18-4 port0 configuration during reset the pins that control the operation of the internal control logic, the clock configuration, and the reserved pins are evaluated only during a hardware triggered reset sequence. the pins that influence the configuration of the c161pi are evaluated during any reset sequence, i.e. also during software and watchdog timer triggered resets. the configuration via p0h is latched in register rp0h for subsequent evaluation by software. register rp0h is described in chapter ? the external bus interface ? . the following describes the different selections that are offered for reset configuration. the default modes refer to pins at high level, i.e. without external pulldown devices connected. please also consider the note above. rp0h port 4 logic port 6 logic syscon buscon0 internal control logic (only on hardware reset) clock generator h.7 h.6 h.5 h.4 h.3 h.2 h.1 h.0 l.7 l.6 l.5 l.4 l.3 l.2 l.1 l.0 clkcfg salsel cssel wr c bustyp smod adp emu rd
 #) user ? s manual 18-14 1999-08  emulation mode pin p0l.0 (emu) selects the emulation mode, when latched low at the end of reset. this mode is used for special emulation and testing purposes and is of minor use for standard c161pi applications, so p0l.0 should be held high. emulation mode provides access to integrated xbus peripherals via the external bus interface pins (direction reversed) of the c161pi. the cpu and the generic peripherals are disabled, all modules connected via the xbus are active. default: emulation mode is off. note: in emulation mode pin p0.15 (p0h.7) is inverted, i.e. the configuration ? 111 ? would select direct drive in emulation mode. emulation mode can only be activated upon an external reset (ea = ? 0 ? ). pin p0l.0 is not evaluated upon a single-chip reset (ea = ? 1 ? ). table 18-1 emulation mode summary pin(s) function notes port 4, port1 address input the segment address lines configured at reset must be driven externally port0 data input/output rd , wr control signal input ale unused input hold low clkout cpu clock output enabled automatically rstout reset input drive externally for an xbus peripheral reset rstin reset input standard reset for complete device port 6 interrupt output sends xbus peripheral interrupt request e.g. to the emulation system
 #) user ? s manual 18-15 1999-08  adapt mode pin p0l.1 (adp) selects the adapt mode, when latched low at the end of reset. in this mode the c161pi goes into a passive state, which is similar to its state during reset. the pins of the c161pi float to tristate or are deactivated via internal pullup/pulldown devices, as described for the reset state. in addition also the rstout pin floats to tristate rather than be driven low. the on-chip oscillator and the realtime clock are disabled. this mode allows switching a c161pi that is mounted to a board virtually off, so an emulator may control the board ? s circuitry, even though the original c161pi remains in its place. the original c161pi also may resume to control the board after a reset sequence with p0l.1 high. please note that adapt mode overrides any other configuration via port0. default: adapt mode is off. note: when xtal1 is fed by an external clock generator (while xtal2 is left open), this clock signal may also be used to drive the emulator device. however, if a crystal is used, the emulator device ? s oscillator can use this crystal only, if at least xtal2 of the original device is disconnected from the circuitry (the output xtal2 will be driven high in adapt mode). adapt mode can only be activated upon an external reset (ea = ? 0 ? ). pin p0l.1 is not evaluated upon a single-chip reset (ea = ? 1 ? ).
 #) user ? s manual 18-16 1999-08  special operation modes pins p0l.5 to p0l.2 (smod) select special operation modes of the c161pi during reset (see table below). make sure to only select valid configurations in order to ensure proper operation of the c161pi. the on-chip bootstrap loader allows moving the start code into the internal ram of the c161pi via the serial interface asc0. the c161pi will remain in bootstrap loader mode until a hardware reset not selecting bsl mode or a software reset. default: the c161pi starts fetching code from location 00 ? 0000 h , the bootstrap loader is off. table 18-2 definition of special modes for reset configuration p0.5-2 (p0l.5-2) special mode notes 1 1 1 1 normal start default configuration. begin of execution as defined via pin ea . 1 1 1 0 reserved do not select this configuration! 1 1 0 1 reserved do not select this configuration! 1 1 0 0 reserved do not select this configuration! 1 0 1 1 standard bootstrap loader load an initial boot routine of 32 bytes via interface asc0. 1 0 1 0 reserved do not select this configuration! 1 0 0 1 alternate boot operation not yet defined. do not use! 1 0 0 0 reserved do not select this configuration! 0 1 1 1 no emulation mode: alternate start operation not yet defined. do not use! 0 1 1 0 reserved do not select this configuration! 0 1 0 1 reserved do not select this configuration! 0 1 0 0 reserved do not select this configuration! 0 0 x x reserved do not select this configuration!
 #) user ? s manual 18-17 1999-08  external bus type pins p0l.7 and p0l.6 (bustyp) select the external bus type during reset, if an external start is selected via pin ea . this allows the configuration of the external bus interface of the c161pi even for the first code fetch after reset. the two bits are copied into bit field btyp of register buscon0. p0l.7 controls the data bus width, while p0l.6 controls the address output (multiplexed or demultiplexed ). this bit field cannot be changed via software after reset. port0 and port1 are automatically switched to the selected bus mode. in multiplexed bus modes port0 drives both the 16-bit intra-segment address and the output data, while port1 remains in high impedance state as long as no demultiplexed bus is selected via one of the buscon registers. in demultiplexed bus modes port1 drives the 16-bit intra-segment address, while port0 or p0l (according to the selected data bus width) drives the output data. for a 16-bit data bus bhe is automatically enabled, for an 8-bit data bus bhe is disabled via bit bytdis in register syscon. default: 16-bit data bus with multiplexed addresses. note: if an internal start is selected via pin ea , these two pins are disregarded and bit field btyp of register buscon0 is cleared. write configuration pin p0h.0 (wrc) selects the initial operation of the control pins wr and bhe during reset. when high, this pin selects the standard function, i.e. wr control and bhe . when low, it selects the alternate configuration, i.e. wrh and wrl . thus even the first access after a reset can go to a memory controlled via wrh and wrl . this bit is latched in register rp0h and its inverted value is copied into bit wrcfg in register syscon. default: standard function (wr control and bhe ). table 18-3 configuration of external bus type p0l.7-6 (btyp) encoding external data bus width external address bus mode 0 0 8-bit data demultiplexed addresses 0 1 8-bit data multiplexed addresses 1 0 16-bit data demultiplexed addresses 1 1 16-bit data multiplexed addresses
 #) user ? s manual 18-18 1999-08  chip select lines pins p0h.2 and p0h.1 (cssel) define the number of active chip select signals during reset. this allows the selection which pins of port 6 drive external cs signals and which are used for general purpose io. the two bits are latched in register rp0h. default: all 5 chip select lines active (cs4 ...cs0 ) . note: the selected number of cs signals cannot be changed via software after reset. segment address lines pins p0h.4 and p0h.3 (salsel) define the number of active segment address lines during reset. this allows the selection which pins of port 4 drive address lines and which are used for general purpose io. the two bits are latched in register rp0h. depending on the system architecture the required address space is chosen and accessible right from the start, so the initialization routine can directly access all locations without prior programming. the required pins of port 4 are automatically switched to address output mode. even if not all segment address lines are enabled on port 4, the c161pi internally uses its complete 24-bit addressing mechanism. this allows the restriction of the width of the effective address bus, while still deriving cs signals from the complete addresses. default: 2-bit segment address (a17...a16) allowing access to 256 kbyte. note: the selected number of segment address lines cannot be changed via software after reset. table 18-4 configuration of chip select lines p0h.2-1 (cssel) chip select lines note 1 1 five: cs4 ...cs0 default without pull-downs 1 0 none port 6 pins free for io 0 1 two: cs1 ...cs0 0 0 three: cs2 ...cs0 table 18-5 configuration of segment address lines p0h.4-3 (salsel) segment address lines directly accessible address space 1 1 two: a17...a16 256 kbyte (default without pull-downs) 1 0 seven: a22...a16 8 mbyte (maximum) 0 1 none 64 kbyte (minimum) 0 0 four: a19...a16 1 mbyte
 #) user ? s manual 18-19 1999-08  clock generation control pins p0h.7, p0h.6 and p0h.5 (clkcfg) select the basic clock generation mode during reset. the oscillator clock either directly feeds the cpu and peripherals (direct drive), it is divided by 2 or it is fed to the on-chip pll which then provides the cpu clock signal (selectable multiple of the oscillator frequency, i.e. the input frequency). these bits are latched in register rp0h. default: on-chip pll is active with a factor of 1:4. watch the different requirements for frequency and duty cycle of the oscillator input clock for the possible selections. oscillator watchdog control the on-chip oscillator watchdog (owd) may be disabled via hardware by (externally) pulling the rd line low upon a reset, similar to the standard reset configuration via port0. at the end of any reset bit owddis in register syscon reflects the inverted level of pin rd at that time. the software may again enable the oscillator watchdog by clearing bit owddis before the execution of einit. note: if direct drive or prescaler operation is selected as basic clock generation mode (see above) the pll is switched off whenever bit owddis is set (via software or via hardware configuration). table 18-6 c161pi clock generation modes p0.15-13 (p0h.7-5) cpu frequency f cpu = f osc * f external clock input range 1) 1) the external clock input range refers to a cpu clock range of 10...25 mhz. notes 111 f osc * 4 2.5 to 6.25 mhz default configuration 110 f osc * 3 3.33 to 8.33 mhz 101 f osc * 2 5 to 12.5 mhz 100 f osc * 5 2 to 5 mhz 011 f osc * 1 1 to 25 mhz direct drive 2) 2) the maximum frequency depends on the duty cycle of the external clock signal. in emulation mode pin p0.15 (p0h.7) is inverted, i.e. the configuration ? 111 ? would select direct drive in emulation mode. 010 f osc * 1.5 6.66 to 16.6 mhz 001 f osc / 2 2 to 50 mhz cpu clk. via prescaler 000 f osc * 2.5 4 to 10 mhz
 #) user ? s manual 18-20 1999-08  18.4.2 system startup configuration upon a single-chip mode reset for a single-chip mode reset (indicated by ea = ? 1 ? ) the configuration is also latched via port0. however, program execution starts out of the on-chip program memory rather than out of external memory. note: as the c161pi does not provide on-chip program memory a single chip mode reset only makes sense when the bootstrap loader is activated. external resources (memory) may then be activated afterwards via software.
   user ? s manual 19-1 1999-08  19 power management for an increasing number of microcontroller based systems it is an important objective to reduce the power consumption of the system as much as possible. a contradictory objective is, however, to reach a certain level of system performance. besides optimization of design and technology a microcontroller ? s power consumption can generally be reduced by lowering its operating frequency and/or by reducing the circuitry that is clocked. the architecture of the c161pi provides three major means of reducing its power consumption (see figure below) under software control:  reduction of the cpu frequency for slow down operation (flexible clock generation management)  selection of the active peripheral modules (flexible peripheral management)  special operating modes to deactivate cpu, ports and control logic (idle, sleep, power down) this enables the application (i.e. the programmer) to choose the optimum constellation for each operating condition, so the power consumption can be adapted to conditions like maximum performance, partial performance, intermittend operation or standby. intermittend operation (i.e. alternating phases of high performance and power saving) is supported by the cyclic interrupt generation mode of the on-chip rtc (real time clock). figure 19-1 power reduction possibilities power no. of act. peripherals f cpu p ow e r d o w n i d l e a c t i v e
   user ? s manual 19-2 1999-08  these three means described above can be applied independent from each other and thus provide a maximum of flexibility for each application. for the basic power reduction modes (idle, power down) there are dedicated instructions, while special registers control clock generation (syscon2) and peripheral management (syscon3). three different general power reduction modes with different levels of power reduction have been implemented in the c161pi, which may be entered under software control. in idle mode the cpu is stopped, while the (enabled) peripherals continue their operation. idle mode can be terminated by any reset or interrupt request. in sleep mode both the cpu and the peripherals are stopped. the real time clock and its selected oscillator may optionally be kept running. sleep mode can be terminated by any reset or interrupt request (mainly hardware requests, stopped peripherals cannot generate interrupt requests). in power down mode both the cpu and the peripherals are stopped. the real time clock and its selected oscillator may optionally be kept running. power down mode can only be terminated by a hardware reset. note: all external bus actions are completed before a power saving mode is entered. however, power saving modes are not entered if ready is enabled, but has not been activated (driven low) during the last bus access. in addition the power management selects the current cpu frequency and controls which peripherals are active. during slow down operation the basic clock generation path is bypassed and the cpu clock is generated via the programmable slow down divider (sdd) from the selected oscillator clock signal. peripheral management disables and enables the on-chip peripheral modules independently, reducing the amount of clocked circuitry including the respective clock drivers.
   user ? s manual 19-3 1999-08  19.1 idle mode the power consumption of the c161pi microcontroller can be decreased by entering idle mode. in this mode all enabled peripherals, including the watchdog timer, continue to operate normally, only the cpu operation is halted and the on-chip memory modules are disabled. note: peripherals that have been disabled via software also remain disabled after entering idle mode, of course. idle mode is entered after the idle instruction has been executed and the instruction before the idle instruction has been completed (bitfield sleepcon in register syscon1 must be ? 00 b ? ). to prevent unintentional entry into idle mode, the idle instruction has been implemented as a protected 32-bit instruction. idle mode is terminated by interrupt requests from any enabled interrupt source whose individual interrupt enable flag was set before the idle mode was entered, regardless of bit ien. for a request selected for cpu interrupt service the associated interrupt service routine is entered if the priority level of the requesting source is higher than the current cpu priority and the interrupt system is globally enabled. after the reti (return from interrupt) instruction of the interrupt service routine is executed the cpu continues executing the program with the instruction following the idle instruction. otherwise, if the interrupt request cannot be serviced because of a too low priority or a globally disabled interrupt system the cpu immediately resumes normal program execution with the instruction following the idle instruction. for a request which was programmed for pec service a pec data transfer is performed if the priority level of this request is higher than the current cpu priority and the interrupt system is globally enabled. after the pec data transfer has been completed the cpu remains in idle mode. otherwise, if the pec request cannot be serviced because of a too low priority or a globally disabled interrupt system the cpu does not remain in idle mode but continues program execution with the instruction following the idle instruction.
   user ? s manual 19-4 1999-08  figure 19-2 transitions between idle mode and active mode idle mode can also be terminated by a non-maskable interrupt, i.e. a high to low transition on the nmi pin. after idle mode has been terminated by an interrupt or nmi request, the interrupt system performs a round of prioritization to determine the highest priority request. in the case of an nmi request, the nmi trap will always be entered. any interrupt request whose individual interrupt enable flag was set before idle mode was entered will terminate idle mode regardless of the current cpu priority. the cpu will not go back into idle mode when a cpu interrupt request is detected, even when the interrupt was not serviced because of a higher cpu priority or a globally disabled interrupt system (ien= ? 0 ? ). the cpu will only go back into idle mode when the interrupt system is globally enabled (ien= ? 1 ? ) and a pec service on a priority level higher than the current cpu level is requested and executed. note: an interrupt request which is individually enabled and assigned to priority level 0 will terminate idle mode. the associated interrupt vector will not be accessed, however. the watchdog timer may be used to monitor the idle mode: an internal reset will be generated if no interrupt or nmi request occurs before the watchdog timer overflows. to prevent the watchdog timer from overflowing during idle mode it must be programmed to a reasonable time interval before idle mode is entered. active mode idle mode idle instruction cpu interrupt request denied pec request executed pec request denied accepted
   user ? s manual 19-5 1999-08  19.2 sleep mode to further reduce the power consumption the microcontroller can be switched to sleep mode. clocking of all internal blocks is stopped (rtc and selected oscillator optionally), the contents of the internal ram, however, are preserved through the voltage supplied via the v dd pins. the watchdog timer is stopped in sleep mode. sleep mode is selected via bitfield sleepcon in register syscon1 and is entered after the idle instruction has been executed and the instruction before the idle instruction has been completed. sleep mode is terminated by interrupt requests from any enabled interrupt source whose individual interrupt enable flag was set before the idle mode was entered, regardless of bit ien. mainly these are external interrupts and the rtc (if running). note: the receive lines of serial interfaces may be internally routed to external interrupt inputs (see exisel). all peripherals except for the rtc are stopped and hence cannot generate an interrupt request. the realtime clock (rtc) can be kept running in sleep mode in order to maintain a valid system time as long as the supply voltage is applied. this enables a system to determine the current time and the duration of the period while it was down (by comparing the current time with a timestamp stored when sleep mode was entered). the supply current in this case remains well below 1 ma. during sleep mode the voltage at the v dd pins can be lowered to 2.7 v while the rtc and its selected oscillator will still keep on running and the contents of the internal ram will still be preserved. when the rtc (and oscillator) is disabled the internal ram is preserved down to a voltage of 2.5 v. note: when the rtc remains active in sleep mode also the oscillator which generates the rtc clock signal will keep on running, of course. if the supply voltage is reduced the specified maximum cpu clock frequency for this case must be respected. for wakeup (input edge recognition and cpu start) the power must be within the specified limits, however. the total power consumption in sleep mode depends on the active circuitry (i.e. rtc on or off) and on the current that flows through the port drivers. individual port drivers can be disabled simply by configuring them for input. the bus interface pins can be separately disabled by releasing the external bus (disable all address windows by clearing the busact bits) and switching the ports to input (if necessary). of course the required software in this case must be executed from internal memory.
   user ? s manual 19-6 1999-08  note: syscon1 is write protected after the execution of einit unless it is released via the unlock sequence. syscon1 system control register 1 esfr (f1dc h /ee h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 --------------sleepcon - - - - - - - - - - - - - - rw bit function sleepcon sleep mode configuration (mode entered upon the idle instruction) 00: normal idle mode 01: sleep mode, with rtc running 10: reserved. 11: sleep mode, with rtc and oscillator stopped
   user ? s manual 19-7 1999-08  19.3 power down mode the microcontroller can be switched to power down mode which reduces the power consumption to a minimum. clocking of all internal blocks is stopped (rtc and selected oscillator optionally), the contents of the internal ram, however, are preserved through the voltage supplied via the v dd pins. the watchdog timer is stopped in power down mode. this mode can only be terminated by an external hardware reset, i.e. by asserting a low level on the rstin pin. this reset will initialize all sfrs and ports to their default state, but will not change the contents of the internal ram. there are two levels of protection against unintentionally entering power down mode. first, the pwrdn (power down) instruction which is used to enter this mode has been implemented as a protected 32-bit instruction. second, this instruction is effective only if the nmi (non maskable interrupt) pin is externally pulled low while the pwrdn instruction is executed. the microcontroller will enter power down mode after the pwrdn instruction has completed. this feature can be used in conjunction with an external power failure signal which pulls the nmi pin low when a power failure is imminent. the microcontroller will enter the nmi trap routine which can save the internal state into ram. after the internal state has been saved, the trap routine may then execute the pwrdn instruction. if the nmi pin is still low at this time, power down mode will be entered, otherwise program execution continues. the initialization routine (executed upon reset) can check the reset identification flags in register wdtcon to determine whether the controller was initially switched on, or whether it was properly restarted from power down mode. the realtime clock (rtc) can be kept running in power down mode in order to maintain a valid system time as long as the supply voltage is applied. this enables a system to determine the current time and the duration of the period while it was down (by comparing the current time with a timestamp stored when power down mode was entered). the supply current in this case remains well below 1 ma. during power down the voltage at the v dd pins can be lowered to 2.7 v while the rtc and its selected oscillator will still keep on running and the contents of the internal ram will still be preserved. when the rtc (and oscillator) is disabled the internal ram is preserved down to a voltage of 2.5 v. note: when the rtc remains active in power down mode also the oscillator which generates the rtc clock signal will keep on running, of course. if the supply voltage is reduced the specified maximum cpu clock frequency for this case must be respected.
   user ? s manual 19-8 1999-08  the total power consumption in power down mode depends on the active circuitry (i.e. rtc on or off) and on the current that flows through the port drivers. to minimize the consumed current the rtc and/or all pin drivers can be disabled (pins switched to tristate) via a central control bitfield in register syscon2. if an application requires one or more port drivers to remain active even in power down mode also individual port drivers can be disabled simply by configuring them for input. the bus interface pins can be separately disabled by releasing the external bus (disable all address windows by clearing the busact bits) and switching the ports to input (if necessary). of course the required software in this case must be executed from internal memory. 19.3.1 status of output pins during power reduction modes during idle mode the cpu clocks are turned off, while all peripherals continue their operation in the normal way. therefore all ports pins, which are configured as general purpose output pins, output the last data value which was written to their port output latches. if the alternate output function of a port pin is used by a peripheral, the state of the pin is determined by the operation of the peripheral. port pins which are used for bus control functions go into that state which represents the inactive state of the respective function (e.g. wr ), or to a defined state which is based on the last bus access (e.g. bhe ). port pins which are used as external address/data bus hold the address/data which was output during the last external memory access before entry into idle mode under the following conditions: p0h outputs the high byte of the last address if a multiplexed bus mode with 8-bit data bus is used, otherwise p0h is floating. p0l is always floating in idle mode. port1 outputs the lower 16 bits of the last address if a demultiplexed bus mode is used, otherwise the output pins of port1 represent the port latch data. port 4 outputs the segment address for the last access on those pins that were selected during reset, otherwise the output pins of port 4 represent the port latch data. during sleep mode the oscillator (except for rtc operation) and the clocks to the cpu and to the peripherals are turned off. like in idle mode, all port pins which are configured as general purpose output pins output the last data value which was written to their port output latches. when the alternate output function of a port pin is used by a peripheral the state of this pin is determined by the last action of the peripheral before the clocks were switched off.
   user ? s manual 19-9 1999-08  during power down mode the oscillator (except for rtc operation) and the clocks to the cpu and to the peripherals are turned off. like in idle mode, all port pins which are configured as general purpose output pins output the last data value which was written to their port output latches. when the alternate output function of a port pin is used by a peripheral the state of this pin is determined by the last action of the peripheral before the clocks were switched off. note: all pin drivers can be switched off by selecting the general port disable function prior to entering power down mode. when the supply voltage is lowered in power down mode the high voltage of output pins will decrease accordingly. table 19-1 state of c161pi output pins during idle and power down mode . c161pi output pin(s) external bus enabled no external bus idle mode sleep and power down idle mode sleep and power down clkout active (toggling) high active (toggling) high fout active (toggling) hold (high or low) active (toggling) hold (high or low) ale low low rd, wr high high p0l floating port latch data p0h a15...a8 1) / float 1) for multiplexed buses with 8-bit data bus. port latch data port1 last address 2) / port latch data 2) for demultiplexed buses. port latch data port 4 port latch data / last segment port latch data bhe last value port latch data csx last value 3) 3) the cs signal that corresponds to the last address remains active (low), all other enabled cs signals remain inactive (high). by accessing an on-chip x-periperal prior to entering a power save mode all external cs signals can be deactivated. port latch data rstout high if einit was executed before entering idle or power down mode, low otherwise. other port output pins port latch data / alternate function
   user ? s manual 19-10 1999-08  19.4 slow down operation a separate clock path can be selected for slow down operation bypassing the basic clock path used for standard operation. the programmable slow down divider (sdd) divides the oscillator frequency by a factor of 1...32 which is specified via bitfield clkrel in register syscon2 (factor = +1). when bitfield clkrel is written during sdd operation the reload counter will output one more clock pulse with the ? old ? frequency in order to resynchronize internally before generating the ? new ? frequency. if direct drive mode is configured clock signal f dd is directly fed to f cpu , if prescaler mode is configured clock signal f dd is additionally divided by 2:1 to generate f cpu (see examples below). figure 19-3 slow down divider operation using e.g. a 5 mhz input clock the on-chip logic may be run at a frequency down to 156.25 khz (or 78 khz) without an external hardware change. an implemented pll may be switched off in this case or kept running, depending on the requirements of the application (see table below). note: during slow down operation the whole device (including bus interface and generation of signals clkout or fout) is clocked with the sdd clock (see figure above). clkrel f osc f sdd f osc f sdd factor=3, direct drive factor=5, direct drive reload counter factor=3, prescaler
   user ? s manual 19-11 1999-08  all these clock options are selected via bitfield clkcon in register syscon2. a state machine controls the switching mechanism itself and ensures a continuous and glitch- free clock signal to the on-chip logic. this is especially important when switching back to pll frequency when the pll has temporarily been switched off. in this case the clock source can be switched back either automatically as soon as the pll is locked again (indicated by bit clklock in register syscon2), or manually, i.e. under software control, after bit clklock has become ? 1 ? . the latter way is preferable if the application requires a defined point where the frequency changes. switching to slow down operation affects frequency sensitive peripherals like serial interfaces, timers, pwm, etc. if these units are to be operated in slow down mode their precalers or reload values must be adapted. please note that the reduced cpu frequency decreases e.g. timer resolution and increases the step width e.g. for baudrate generation. the oscillator frequency in such a case should be chosen to accomodate the required resolutions and/or baudrates. table 19-2 pll operation (if available) in slow down mode advantage disadvantage oscillator watchdog pll running fast switching back to basic clock source pll adds to power consumption active if not disabled via bit owddis pll off pll causes no additional power consumption pll must lock before switching back to the basic clock source (if the pll is the basic clock source) disabled
   user ? s manual 19-12 1999-08  note: syscon2 (except for bitfield sysrls, of course) is write protected after the execution of einit unless it is released via the unlock sequence. syscon2 system control register 2 esfr (f1d0 h /e8 h ) reset value: 00x0 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 clk lock clkrel clkcon scs rcs pdcon sysrls rh rw rw rw rw rw rwh bit function sysrls syscon release function (unlock field) must be written in a defined way in order to execute the unlock sequence. see separate description pdcon power down control (during power down mode) 00: rtc = on, ports = on (default after reset). 01: rtc = on, ports = off. 10: rtc = off, ports = on. 11: rtc = off, ports = off. rcs rtc clock source (not affected by a reset) 0: main oscillator. 1: reserved. scs sdd clock source (not affected by a reset) 0: main oscillator. 1: reserved. clkcon clock state control 00: running on configured basic frequency. 01: running on slow down frequency, pll on if implemented. 10: running on slow down frequency, pll off if implemented. 11: reserved. do not use this combination. clkrel reload counter value for slowdown divider (sdd factor = clkrel+1) clklock clock signal status bit 0: main oscillator is unstable or pll is unlocked (if pll is implemented). 1: main oscillator is stable and pll is locked (if pll is implemented). if no pll is implemented it is assumed to be always locked.
   user ? s manual 19-13 1999-08  figure 19-4 clock switching state machine note: when the pll is the basic clock source and a reset occurs during sdd operation with the pll off, the internal reset condition is extended so the pll can lock before execution begins. the reset condition is terminated prematurely if no stable oscillator clock is detected. this ensures the operability of the device in case of a missing input clock signal. table 19-3 clock switching state description state number pll status f cpu source clk con note 1locked 1) 1) the indicated pll status only applies if the pll is selected as the basic clock source. if the basic clock source is direct drive or prescaler the pll will not lock. if the oscillator watchdog is disabled (owddis= ? 1 ? ) the pll will be off. basic 00 standard operation on basic clock frequency. 2locked 1) sdd 01 sdd operation with pll on 1) . fast (without delay) or manual switch back (from 5) to basic clock frequency. 3 transient 1) sdd (00) intermediate state leading to state 1. 4 transient 1) sdd (01) intermediate state leading to state 2. 5 off sdd 10 sdd operation with pll off. reduced power consumption. 2 1 4 3 5 reset 00 00 0 0 01 01 1 0 1 0 1 0 1 0 0 1 xx state transition when writing ? xx ? to clkcon. automatic transition after clock is stable, i.e. clklock = ? 1 ? .
   user ? s manual 19-14 1999-08  19.5 flexible peripheral management the power consumed by the c161pi also depends on the amount of active logic. peripheral management enables the system designer to deactivate those on-chip peripherals that are not required in a given system status (e.g. a certain interface mode or standby). all modules that remain active, however, will still deliver their usual performance. if all modules that are fed by the peripheral clock driver (pcd) are disabled and also the other functions fed by the pcd are not required, this clock driver itself may also be disabled to save additional power. this flexibility is realized by distributing the cpu clock via several clock drivers which can be separately controlled, and may also be smaller. figure 19-5 cpu clock distribution note: the real time clock (rtc) is fed by a separate clock driver, so it can be kept running even in power down mode while still all the other circuitry is disconnected from the clock. the registers of the generic peripherals can be accessed even while the respective module is disabled, as long as pcd is running (the registers of peripherals which are connected to icd can be accessed even in this case, of course). the registers of x- peripherals cannot be accessed while the respective module is disabled by any means. while a peripheral is disabled its output pins remain in the state they had at the time of disabling. software controls this flexible peripheral mangement via register syscon3 where each control bit is associated with an on-chip peripheral module. clock generation rtc cpu peripherals, interface ports, intr.ctrl. ccd pcd icd idle mode pcddis peripherals, fout
   user ? s manual 19-15 1999-08  note: the allocation of peripheral disable bits within register syscon3 is device specific and may be different in other derivatives than the c161pi. syscon3 is write protected after the execution of einit unless it is released via the unlock sequence. when disabling the peripheral clock driver (pcd), the following details should be respected:  the clock signal for all connected peripherals is stopped. make sure that all peripherals enter a safe state before disabling pcd.  the output signal clkout will remain high (fout will keep on toggling).  interrupt requests will still be recognized even while pcd is disabled.  no new output values are gated from the port output latches to the output port pins and no new input values are latched from the input port pins.  no register access is possible for generic peripherals (reg. access is possible for individually disabled generic peripherals, no reg. access at all is possible for disabled x-peripherals) syscon3 system control register 3 esfr (f1d4 h /ea h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 pcd dis --- i 2 c dis -- ----- gpt dis ssc dis asc0 dis adc dis rw - - - rw - - - - - - - rw rw rw rw bit function (associated peripheral module) adcdis analog/digital converter asc0dis usart asc0 sscdis synchronous serial channel ssc gptdis general purpose timer blocks i 2 cdis on-chip i 2 c bus module pcddis peripheral clock driver (also x-peripherals)
   user ? s manual 19-16 1999-08  19.6 programmable frequency output signal the system clock output (clkout) can be replaced by the programmable frequency output signal f out . this signal can be controlled via software (contrary to clkout), and so can be adapted to the requirements of the connected external circuitry. the programmability also extends the power management to a system level, as also circuitry (peripherals, etc.) outside the c161pi can be influenced, i.e. run at a scalable frequency or temporarily can be switched off completely. this clock signal is generated via a reload counter, so the output frequency can be selected in small steps. an optional toggle latch provides a clock signal with a 50% duty cycle. figure 19-6 clock output signal generation signal f out always provides complete output periods (see signal waveforms below):  when f out is started (foen--> ? 1 ? ) focnt is loaded from forv  when f out is stopped (foen--> ? 0 ? ) focnt is stopped when f out has reached (or is) ? 0 ? . signal f out is independent from the peripheral clock driver pcd. while clkout would stop when pcd is disabled, f out will keep on toggling. thus external circuitry may be controlled independent from on-chip peripherals. note: counter focnt is clocked with the cpu clock signal f cpu (see figure above) and therefore will also be influenced by the sdd operation. register focon provides control over the output signal generation (frequency, waveform, activation) as well as all status information (counter value, fotl). foss focnt f out forv mux f cpu fotl ctrl. foen
   user ? s manual 19-17 1999-08  note: it is not recommended to write to any part of bitfield focnt, especially not while the counter is running. writing to focnt prior to starting the counter is obsolete because it will immediatley be reloaded from forv. writing to focnt during operation may produce unintended counter values. signal f out in the c161pi is an alternate output function and shares a port pin with signal clkout. a priority ranking determines which function controls the shared pin: note: for the generation of f out pin fout must be switched to output, i.e. dp3.15= ? 1 ? . while f out is disabled the pin is controlled by the port latch (see figure above). the port latch p3.15 must be ? 0 ? in order to maintain the f out inactive level on the pin. focon frequency output ctrl. reg. sfr (ffaa h /d5 h ) reset value: 0000 h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 foen foss forv - fotl f ocnt rw rw rw rwh rwh bit function focnt frequency output counter fotl frequency output toggle latch is toggled upon each underflow of focnt. forv frequency output reload value is copied to focnt upon each underflow of focnt. foss frequency output signal select 0: output of the toggle latch: dc=50%. 1: output of the reload counter: dc depends on forv. foen frequency output enable 0: frequency output generation stops when signal f out is/gets low. 1: focnt is running, f out is gated to pin. 1st reload after 0-1 transition. table 19-4 priority ranking for shared output pin priority function control 1 clkout clken = ? 1 ? , foen = ? x ? 2fout clken = ? 0 ? , foen = ? 1 ? 3 gen. purpose io clken = ? 0 ? , foen = ? 0 ?
   user ? s manual 19-18 1999-08  figure 19-7 connection to port logic (functional approach) figure 19-8 signal waveforms note: the output signal (for foss= ? 1 ? ) is high for the duration of 1 f cpu cycle for all reload values forv > 0. for forv = 0 the output signal corresponds to f cpu . f out mux f cpu ? 1 ? direction portlatch 0 1 mux 0 1 fout_active clken mux 0 1 f cpu f out f out 1) 2) 1) 2) 1) foss= ? 1 ? , output of counter 2) foss= ? 0 ? , output of toggle latch foen--> ? 1 ? foen--> ? 0 ? (forv=0) (forv=5) f out 1) 2) (forv=2) the counter stops here the counter starts here
   user ? s manual 19-19 1999-08  output frequency calculation the output frequency can be calculated as f out = f cpu / ( (forv+1) * 2 (1-foss) ), so f outmin = f cpu / 128 (forv = 3f h , foss = ? 0 ? ), and f outmax = f cpu / 1 (forv = 00 h , foss = ? 1 ? ). table 19-5 selectable output frequency range for f out . f cpu f out in khz for forv=xx, foss=1/0 forv for f out =1 mhz 00 h 01 h 02 h 3e h 3f h foss=0 foss=1 4 mhz 4000 2000 2000 1000 1333.33 666.667 63.492 31.746 62.5 31.25 01 h 03 h 10 mhz 10000 5000 5000 2500 3333.33 1666.667 158.73 79.365 156.25 78.125 04 h 09 h 12 mhz 12000 6000 6000 3000 4000 2000 190.476 95.238 187.5 93.75 05 h 0b h 16 mhz 16000 8000 8000 4000 5333.33 2666.667 253.968 126.984 250 125 07 h 0f h 20 mhz 20000 10000 10000 5000 6666.667 3333.33 317.46 158.73 312.5 156.25 09 h 13 h 25 mhz 25000 12500 12500 6250 8333.33 4166.667 396.825 198.4126 390.625 195.3125 0c h (1.04167) 17 h
   user ? s manual 19-20 1999-08  19.7 security mechanism the power management control registers (syscon1, syscon2, syscon3) control functions and modes which are critical for the c161pi ? s operation. for this reason they are locked (except for bitfield sysrls in register syscon2) after the execution of einit (like register syscon) so these vital system functions cannot be changed inadvertently e.g. by software errors. however, as these registers control the power management they need to be accessed during operation to select the appropriate mode. the system control software gets this access via a special unlock sequence which allows one single write access to either syscon1, syscon2, or syscon3 when executed properly. this provides a maximum of security. note: of course syscon1, syscon2, and syscon3 may be read at any time without restrictions. the unlock sequence is executed by writing defined values to bitfield sysrls using defined instructions (see table below). the instructions of the unlock sequence (including the intended write access) must be secured with an extr instruction (switch to esfr space and lock interrupts). note: the unlock sequence is aborted if the locked range (extr) does not cover the complete sequence. the unlock sequence provides no write access to register syscon. table 19-6 syscon2/syscon3 unlock sequence step sysrls instruction notes --- 0000 b 1) 1) sysrls must be set to 0000 b before the first step, if any or command is used. --- status before release sequence 1 1001 b bfldl, or, orb 2) , xor, xorb 2) 2) usually byte accesses should not be used for special function registers. read-modify-write access 2 0011 b mov, movb 2) , movbs 2) , movbz 2) write access 3 0111 b bset, bmov 2) , bmovn 2) , bor 2) , bxor 1) read-modify-write access, bit instruction 4 --- --- single (read-modify-)write access to syscon1, syscon2, or syscon3. --- 0000 b 3) 3) sysrls is cleared by hardware if unlock sequence and write access were successful. sysrls shows the last value written otherwise. --- status after release sequence
   user ? s manual 19-21 1999-08  the code examples below show how an access to syscon2/syscon3 can be accomplished in an application. examples where the pll keeps running: enter_slowdown: ;currently running on basic clk. frequency extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to syscon2/syscon3 bfldh syscon2,#03h,#01h ;clkcon=01b --> sdd frequency, pll on exit_slowdown: ;currently running on sdd frequency extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to syscon2/syscon3 bfldh syscon2,#03h,#00h ;clkcon=00b --> basic frequency
   user ? s manual 19-22 1999-08  examples where the pll is disabled: enter_slowdown: ;currently running on basic clk. frequency extr #1h ;next access to esfr space bclr isnc.2 ;pllie= ? 0 ? , i.e. pll interrupt disabled extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to syscon2/syscon3 bfldh syscon2,#03h,#02h ;clkcon=10b --> sdd frequency, pll off sdd_exit_auto: ;currently running on sdd frequency extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to syscon2/syscon3 bfldh syscon2,#03h,#00h ;clkcon=00b --> basic frequ./start pll extr #1h ;next access to esfr space bset isnc.2 ;pllie= ? 1 ? , i.e. pll interrupt enabled sdd_exit_manual: ;currently running on sdd frequency extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to syscon2/syscon3 bfldh syscon2,#03h,#01h ;clkcon=01b --> stay on sdd/start pll user_code: ;space for any user code that... ;...must or can be executed before... ;...switching back to basic clock clock_ok: extr #1h ;next access to esfr space jnb syscon2.15, clock_ok;wait until clklock= ? 1 ? extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to syscon2/syscon3 bfldh syscon2,#03h,#00h ;clkcon=00b --> basic frequency extr #1h ;next access to esfr space bset isnc.2 ;pllie= ? 1 ? , i.e. pll interrupt enabled
 #   user ? s manual 20-1 1999-08  20 system programming to aid in software development, a number of features has been incorporated into the instruction set of the c161pi, including constructs for modularity, loops, and context switching. in many cases commonly used instruction sequences have been simplified while providing greater flexibility. the following programming features help to fully utilize this instruction set. instructions provided as subsets of instructions in many cases, instructions found in other microcontrollers are provided as subsets of more powerful instructions in the c161pi. this allows the same functionality to be provided while decreasing the hardware required and decreasing decode complexity. in order to aid assembly programming, these instructions, familiar from other microcontrollers, can be built in macros, thus providing the same names. directly substitutable instructions are instructions known from other microcontrollers that can be replaced by the following instructions of the c161pi: modification of system flags is performed using bit set or bit clear instructions (bset, bclr). all bit and word instructions can access the psw register, so no instructions like clear carry or enable interrupts are required. external memory data access does not require special instructions to load data pointers or explicitly load and store external data. the c161pi provides a von-neumann memory architecture and its on-chip hardware automatically detects accesses to internal ram, gprs, and sfrs. table 20-1 substitution of instructions substituted instruction c161pi instruction function clr rn and rn, #0 h clear register cplb bit bmovn bit, bit complement bit dec rn sub rn, #1 h decrement register inc rn add rn, #1 h increment register swapb rn ror rn, #8 h swap bytes within word
 #   user ? s manual 20-2 1999-08  multiplication and division multiplication and division of words and double words is provided through multiple cycle instructions implementing a booth algorithm. each instruction implicitly uses the 32-bit register md (mdl = lower 16 bits, mdh = upper 16 bits). the mdriu flag (multiply or divide register in use) in register mdc is set whenever either half of this register is written to or when a multiply/divide instruction is started. it is cleared whenever the mdl register is read. because an interrupt can be acknowledged before the contents of register md are saved, this flag is required to alert interrupt routines, which require the use of the multiply/divide hardware, so they can preserve register md. this register, however, only needs to be saved when an interrupt routine requires use of the md register and a previous task has not saved the current result. this flag is easily tested by the jump-on-bit instructions. multiplication or division is simply performed by specifying the correct (signed or unsigned) version of the multiply or divide instruction. the result is then stored in register md. the overflow flag (v) is set if the result from a multiply or divide instruction is greater than 16 bits. this flag can be used to determine whether both word halfs must be transferred from register md. the high portion of register md (mdh) must be moved into the register file or memory first, in order to ensure that the mdriu flag reflects the correct state. the following instruction sequence performs an unsigned 16 by 16-bit multiplication: save: jnb mdriu, start ;test if md was in use. scxt mdc, #0010h ;save and clear control register, ;leaving mdriu set ;(only required for interrupted ;multiply/divide instructions) bset saved ;indicate the save operation push mdh ;save previous md contents... push mdl ;...on system stack start: mulu r1, r2 ;multiply 16 16 unsigned, sets mdriu jmpr cc_nv, copyl ;test for only 16-bit result mov r3, mdh ;move high portion of md copyl: mov r4, mdl ;move low portion of md, clears mdriu restore: jnb saved, done ;test if md registers were saved pop mdl ;restore registers pop mdh pop mdc bclr saved ;multiplication is completed, ;program continues done: ...
 #   user ? s manual 20-3 1999-08  the above save sequence and the restore sequence after copyl are only required if the current routine could have interrupted a previous routine which contained a mul or div instruction. register mdc is also saved because it is possible that a previous routine ? s multiply or divide instruction was interrupted while in progress. in this case the information about how to restart the instruction is contained in this register. register mdc must be cleared to be correctly initialized for a subsequent multiplication or division. the old mdc contents must be popped from the stack before the reti instruction is executed. for a division the user must first move the dividend into the md register. if a 16/16-bit division is specified, only the low portion of register md must be loaded. the result is also stored into register md. the low portion (mdl) contains the integer result of the division, while the high portion (mdh) contains the remainder. the following instruction sequence performs a 32 by 16-bit division: mov mdh, r1 ;m ove dividend to md register. sets mdriu mov mdl, r2 ;move low portion to md div r3 ;divide 32/16 signed, r3 holds divisor jmpr cc_v, error ;test for divide overflow mov r3, mdh ;move remainder to r3 mov r4, mdl ;move integer result to r4. clears mdriu whenever a multiply or divide instruction is interrupted while in progress, the address of the interrupted instruction is pushed onto the stack and the mulip flag in the psw of the interrupting routine is set. when the interrupt routine is exited with the reti instruction, this bit is implicitly tested before the old psw is popped from the stack. if mulip= ? 1 ? the multiply/divide instruction is re-read from the location popped from the stack (return address) and will be completed after the reti instruction has been executed. note: the mulip flag is part of the context of the interrupted task . when the interrupting routine does not return to the interrupted task (e.g. scheduler switches to another task) the mulip flag must be set or cleared according to the context of the task that is switched to. bcd calculations no direct support for bcd calculations is provided in the c161pi. bcd calculations are performed by converting bcd data to binary data, performing the desired calculations using standard data types, and converting the result back to bcd data. due to the enhanced performance of division instructions binary data is quickly converted to bcd data through division by 10 d . conversion from bcd data to binary data is enhanced by multiple bit shift instructions. this provides similar performance compared to instructions directly supporting bcd data types, while no additional hardware is required.
 #   user ? s manual 20-4 1999-08  20.1 stack operations the c161pi supports two types of stacks. the system stack is used implicitly by the controller and is located in the internal ram. the user stack provides stack access to the user in either the internal or external memory. both stack types grow from high memory addresses to low memory addresses. internal system stack a system stack is provided to store return vectors, segment pointers, and processor status for procedures and interrupt routines. a system register, sp, points to the top of the stack. this pointer is decremented when data is pushed onto the stack, and incremented when data is popped. the internal system stack can also be used to temporarily store data or pass it between subroutines or tasks. instructions are provided to push or pop registers on/from the system stack. however, in most cases the register banking scheme provides the best performance for passing data between multiple tasks. note: the system stack allows the storage of words only. bytes must either be converted to words or the respective other byte must be disregarded. register sp can only be loaded with even byte addresses (the lsb of sp is always ? 0 ? ). detection of stack overflow/underflow is supported by two registers, stkov (stack overflow pointer) and stkun (stack underflow pointer). specific system traps (stack overflow trap, stack underflow trap) will be entered whenever the sp reaches either boundary specified in these registers. the contents of the stack pointer are compared to the contents of the overflow register, whenever the sp is decremented either by a call, push or sub instruction. an overflow trap will be entered, when the sp value is less than the value in the stack overflow register. the contents of the stack pointer are compared to the contents of the underflow register, whenever the sp is incremented either by a ret, pop or add instruction. an underflow trap will be entered, when the sp value is greater than the value in the stack underflow register. note: when a value is moved into the stack pointer, no check against the overflow/ underflow registers is performed. in many cases the user will place a software reset instruction (srst) into the stack underflow and overflow trap service routines. this is an easy approach, which does not require special programming. however, this approach assumes that the defined internal stack is sufficient for the current software and that exceeding its upper or lower boundary represents a fatal error.
 #   user ? s manual 20-5 1999-08  it is also possible to use the stack underflow and stack overflow traps to cache portions of a larger external stack. only the portion of the system stack currently being used is placed into the internal memory, thus allowing a greater portion of the internal ram to be used for program, data or register banking. this approach assumes no error but requires a set of control routines (see below). circular (virtual) stack this basic technique allows pushing until the overflow boundary of the internal stack is reached. at this point a portion of the stacked data must be saved into external memory to create space for further stack pushes. this is called ? stack flushing ? . when executing a number of return or pop instructions, the upper boundary (since the stack empties upward to higher memory locations) is reached. the entries that have been previously saved in external memory must now be restored. this is called ? stack filling ? . because procedure call instructions do not continue to nest infinitely and call and return instructions alternate, flushing and filling normally occurs very infrequently. if this is not true for a given program environment, this technique should not be used because of the overhead of flushing and filling. the basic mechanism is the transformation of the addresses of a virtual stack area, controlled via registers sp, stkov and stkun, to a defined physical stack area within the internal ram via hardware. this virtual stack area covers all possible locations that sp can point to, i.e. 00 ? f000 h through 00 ? fffe h . stkov and stkun accept the same 4 kbyte address range. the size of the physical stack area within the internal ram that effectively is used for standard stack operations is defined via bitfield stksz in register syscon (see below). table 20-2 circular stack address transformation stksz stack size (words) internal ram addresses (words) of physical stack significant bits of stack ptr. sp 0 0 0 b 256 00 ? fbfe h ...00 ? fa00 h (default after reset) sp.8...sp.0 0 0 1 b 128 00 ? fbfe h ...00 ? fb00 h sp.7...sp.0 0 1 0 b 64 00 ? fbfe h ...00 ? fb80 h sp.6...sp.0 0 1 1 b 32 00 ? fbfe h ...00 ? fbc0 h sp.5...sp.0 1 0 0 b 512 00 ? fbfe h ...00 ? f800 h (not for 1kbyte iram) sp.9...sp.0 1 0 1 b --- reserved. do not use this combination. --- 1 1 0 b --- reserved. do not use this combination. --- 1 1 1 b 1024 00 ? fdfe h ...00 ? fx00 h (note: no circular stack) 00 ? fx00 h represents the lower iram limit, i.e. 1kb: 00 ? fa00 h , 2 kb: 00 ? f600 h , 3kb: 00 ? f200 h sp.11...sp.0
 #   user ? s manual 20-6 1999-08  the virtual stack addresses are transformed to physical stack addresses by concatenating the significant bits of the stack pointer register sp (see table) with the complementary most significant bits of the upper limit of the physical stack area (00 ? fbfe h ). this transformation is done via hardware (see figure below). the reset values (stkov=fa00 h , stkun=fc00 h , sp=fc00 h , stksz=000 b ) map the virtual stack area directly to the physical stack area and allow using the internal system stack without any changes, provided that the 256 word area is not exceeded. figure 20-1 physical stack address generation the following example demonstrates the circular stack mechanism which is also an effect of this virtual stack mapping: first, register r1 is pushed onto the lowest physical stack location according to the selected maximum stack size. with the following instruction, register r2 will be pushed onto the highest physical stack location although the sp is decremented by 2 as for the previous push operation. mov sp, #0f802h ;set sp before last entry... ;...of physical stack of 256 words ... ;(sp)=f802h: physical stack addr.=fa02h push r1 ;(sp)=f800h: physical stack addr.=fa00h push r2 ;(sp)=f7feh: physical stack addr.=fbfeh 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 fbfe h fb80 h fb80 h fbfe h fb7e h fbfe h fbfe h 64 words 256 words f800 h 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 fa00 h 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 fbfe h f7fe h fbfe h 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 phys.a. phys.a. stack size after push after push
 #   user ? s manual 20-7 1999-08  the effect of the address transformation is that the physical stack addresses wrap around from the end of the defined area to its beginning. when flushing and filling the internal stack, this circular stack mechanism only requires to move that portion of stack data which is really to be re-used (i.e. the upper part of the defined stack area) instead of the whole stack area. stack data that remain in the lower part of the internal stack need not be moved by the distance of the space being flushed or filled, as the stack pointer automatically wraps around to the beginning of the freed part of the stack area. note: this circular stack technique is applicable for stack sizes of 32 to 512 words (stksz = ? 000 b ? to ? 100 b ? ), it does not work with option stksz = ? 111 b ? , which uses the complete internal ram for system stack. in the latter case the address transformation mechanism is deactivated. when a boundary is reached, the stack underflow or overflow trap is entered, where the user moves a predetermined portion of the internal stack to or from the external stack. the amount of data transferred is determined by the average stack space required by routines and the frequency of calls, traps, interrupts and returns. in most cases this will be approximately one quarter to one tenth the size of the internal stack. once the transfer is complete, the boundary pointers are updated to reflect the newly allocated space on the internal stack. thus, the user is free to write code without concern for the internal stack limits. only the execution time required by the trap routines affects user programs. the following procedure initializes the controller for usage of the circular stack mechanism:  specify the size of the physical system stack area within the internal ram (bitfield stksz in register syscon).  define two pointers, which specify the upper and lower boundary of the external stack. these values are then tested in the stack underflow and overflow trap routines when moving data.  set the stack overflow pointer (stkov) to the limit of the defined internal stack area plus six words (for the reserved space to store two interrupt entries). the internal stack will now fill until the overflow pointer is reached. after entry into the overflow trap procedure, the top of the stack will be copied to the external memory. the internal pointers will then be modified to reflect the newly allocated space. after exiting from the trap procedure, the internal stack will wrap around to the top of the internal stack, and continue to grow until the new value of the stack overflow pointer is reached. when the underflow pointer is reached while the stack is meptied the bottom of stack is reloaded from the external memory and the internal pointers are adjusted accordingly.
 #   user ? s manual 20-8 1999-08  linear stack the c161pi also offers a linear stack option (stksz = ? 111 b ? ), where the system stack may use the complete internal ram area. this provides a large system stack without requiring procedures to handle data transfers for a circular stack. however, this method also leaves less ram space for variables or code. the ram area that may effectively be consumed by the system stack is defined via the stkun and stkov pointers. the underflow and overflow traps in this case serve for fatal error detection only. for the linear stack option all modifiable bits of register sp are used to access the physical stack. although the stack pointer may cover addresses from 00 ? f000 h up to 00 ? fffe h the (physical) system stack must be located within the internal ram and therefore may only use the address range 00 ? f600 h to 00 ? fdfe h . it is the user ? s responsibility to restrict the system stack to the internal ram range. note: avoid stack accesses below the iram area (esfr space and reserved area) and within address range 00 ? fe00 h and 00 ? fffe h (sfr space). otherwise unpredictable results will occur. user stacks user stacks provide the ability to create task specific data stacks and to off-load data from the system stack. the user may push both bytes and words onto a user stack, but is responsible for using the appropriate instructions when popping data from the specific user stack. no hardware detection of overflow or underflow of a user stack is provided. the following addressing modes allow implementation of user stacks: [ ? rw], rb or [ ? rw], rw : pre-decrement indirect addressing. used to push one byte or word onto a user stack. this mode is only available for mov instructions and can specify any gpr as the user stack pointer. rb, [rw i +] or rw, [rw i +] : post-increment index register indirect addressing. used to pop one byte or word from a user stack. this mode is available to most instructions, but only gprs r0-r3 can be specified as the user stack pointer. rb, [rw+] or rw, [rw+] : post-increment indirect addressing. used to pop one byte or word from a user stack. this mode is only available for mov instructions and can specify any gpr as the user stack pointer.
 #   user ? s manual 20-9 1999-08  20.2 register banking register banking provides the user with an extremely fast method to switch user context. a single machine cycle instruction saves the old bank and enters a new register bank. each register bank may assign up to 16 registers. each register bank should be allocated during coding based on the needs of each task. once the internal memory has been partitioned into a register bank space, internal stack space and a global internal memory area, each bank pointer is then assigned. thus, upon entry into a new task, the appropriate bank pointer is used as the operand for the scxt (switch context) instruction. upon exit from a task a simple pop instruction to the context pointer (cp) restores the previous task ? s register bank. 20.3 procedure call entry and exit to support modular programming a procedure mechanism is provided to allow coding of frequently used portions of code into subroutines. the call and ret instructions store and restore the value of the instruction pointer (ip) on the system stack before and after a subroutine is executed. procedures may be called conditionally with instructions calla or calli, or be called unconditionally using instructions callr or calls. note: any data pushed onto the system stack during execution of the subroutine must be popped before the ret instruction is executed. passing parameters on the system stack parameters may be passed via the system stack through push instructions before the subroutine is called, and pop instructions during execution of the subroutine. base plus offset indirect addressing also permits access to parameters without popping these parameters from the stack during execution of the subroutine. indirect addressing provides a mechanism of accessing data referenced by data pointers, which are passed to the subroutine. in addition, two instructions have been implemented to allow one parameter to be passed on the system stack without additional software overhead. the pcall (push and call) instruction first pushes the ? reg ? operand and the ip contents onto the system stack and then passes control to the subroutine specified by the ? caddr ? operand. when exiting from the subroutine, the retp (return and pop) instruction first pops the ip and then the ? reg ? operand from the system stack and returns to the calling program.
 #   user ? s manual 20-10 1999-08  cross segment subroutine calls calls to subroutines in different segments require the use of the calls (call inter- segment subroutine) instruction. this instruction preserves both the csp (code segment pointer) and ip on the system stack. upon return from the subroutine, a rets (return from inter-segment subroutine) instruction must be used to restore both the csp and ip. this ensures that the next instruction after the calls instruction is fetched from the correct segment. note: it is possible to use calls within the same segment, but still two words of the stack are used to store both the ip and csp. providing local registers for subroutines for subroutines which require local storage, the following methods are provided: alternate bank of registers: upon entry into a subroutine, it is possible to specify a new set of local registers by executing the scxt (switch context) instruction. this mechanism does not provide a method to recursively call a subroutine. saving and restoring of registers: to provide local registers, the contents of the registers which are required for use by the subroutine can be pushed onto the stack and the previous values be popped before returning to the calling routine. this is the most common technique used today and it does provide a mechanism to support recursive procedures. this method, however, requires two machine cycles per register stored on the system stack (one cycle to push the register, and one to pop the register). use of the system stack for local registers: it is possible to use the sp and cp to set up local subroutine register frames. this enables subroutines to dynamically allocate local variables as needed within two machine cycles. a local frame is allocated by simply subtracting the number of required local registers from the sp, and then moving the value of the new sp to the cp. this operation is supported through the scxt (switch context) instruction with the addressing mode ? reg, mem ? . using this instruction saves the old contents of the cp on the system stack and moves the value of the sp into cp (see example below). each local register is then accessed as if it was a normal register. upon exit from the subroutine, first the old cp must be restored by popping it from the stack and then the number of used local registers must be added to the sp to restore the allocated local space back to the system stack. note: the system stack is growing downwards, while the register bank is growing upwards.
 #   user ? s manual 20-11 1999-08  figure 20-2 local registers the software to provide the local register bank for the example above is very compact: after entering the subroutine: sub sp, #10d ;free 5 words in the current system stack scxt cp, sp ;set the new register bank pointer before exiting the subroutine: pop cp ;restore the old register bank add sp, #10d ;release the 5 words... ;...of the current system stack old stack area newly allocated register bank r4 r3 r2 r1 r0 old cp contents old sp new sp new cp new stack area
 #   user ? s manual 20-12 1999-08  20.4 table searching a number of features have been included to decrease the execution time required to search tables. first, branch delays are eliminated by the branch target cache after the first iteration of the loop. second, in non-sequentially searched tables, the enhanced performance of the alu allows more complicated hash algorithms to be processed to obtain better table distribution. for sequentially searched tables, the auto-increment indirect addressing mode and the e (end of table) flag stored in the psw decrease the number of overhead instructions executed in the loop. the two examples below illustrate searching ordered tables and non-ordered tables, respectively: mov r0, #base ;move table base into r0 loop: cmp r1, [r0+] ;compare target to table entry jmpr cc_sgt, loop ;test whether target has not been found note: the last entry in the table must be greater than the largest possible target. mov r0, #base ;move table base into r0 loop: cmp r1, [r0+] ;compare target to table entry jmpr cc_net, loop ;test whether target is not found and.. ;..the end of table has not been reached. note: the last entry in the table must be equal to the lowest signed integer (8000 h ). 20.5 floating point support all floating point operations are performed using software. standard multiple precision instructions are used to perform calculations on data types that exceed the size of the alu. multiple bit rotate and logic instructions allow easy masking and extracting of portions of floating point numbers. to decrease the time required to perform floating point operations, two hardware features have been implemented in the cpu core. first, the prior instruction aids in normalizing floating point numbers by indicating the position of the first set bit in a gpr. this result can the be used to rotate the floating point result accordingly. the second feature aids in properly rounding the result of normalized floating point numbers through the overflow (v) flag in the psw. this flag is set when a one is shifted out of the carry bit during shift right operations. the overflow flag and the carry flag are then used to round the floating point result based on the desired rounding algorithm.
 #   user ? s manual 20-13 1999-08  20.6 peripheral control and interface all communication between peripherals and the cpu is performed either by pec transfers to and from internal memory, or by explicitly addressing the sfrs associated with the specific peripherals. after resetting the c161pi all peripherals (except the watchdog timer) are disabled and initialized to default values. a desired configuration of a specific peripheral is programmed using mov instructions of either constants or memory values to specific sfrs. specific control flags may also be altered via bit instructions. once in operation, the peripheral operates autonomously until an end condition is reached at which time it requests a pec transfer or requests cpu servicing through an interrupt routine. information may also be polled from peripherals through read accesses to sfrs or bit operations including branch tests on specific control bits in sfrs. to ensure proper allocation of peripherals among multiple tasks, a portion of the internal memory has been made bit addressable to allow user semaphores. instructions have also been provided to lock out tasks via software by setting or clearing user specific bits and conditionally branching based on these specific bits. it is recommended that bit fields in control sfrs are updated using the bfldh and bfldl instructions or a mov instruction to avoid undesired intermediate modes of operation which can occur, when bclr/bset or and/or instruction sequences are used. 20.7 trap/interrupt entry and exit interrupt routines are entered when a requesting interrupt has a priority higher than the current cpu priority level. traps are entered regardless of the current cpu priority. when either a trap or interrupt routine is entered, the state of the machine is preserved on the system stack and a branch to the appropriate trap/interrupt vector is made. all trap and interrupt routines require the use of the reti (return from interrupt) instruction to exit from the called routine. this instruction restores the system state from the system stack and then branches back to the location where the trap or interrupt occurred.
 #   user ? s manual 20-14 1999-08  20.8 unseparable instruction sequences the instructions of the c161pi are very efficient (most instructions execute in one machine cycle) and even the multiplication and division are interruptable in order to minimize the response latency to interrupt requests (internal and external). in many microcontroller applications this is vital. some special occasions, however, require certain code sequences (e.g. semaphore handling) to be uninterruptable to function properly. this can be provided by inhibiting interrupts during the respective code sequence by disabling and enabling them before and after the sequence. the necessary overhead may be reduced by means of the atomic instruction which allows locking 1...4 instructions to an unseparable code sequence, during which the interrupt system (standard interrupts and pec requests) and class a traps (nmi , stack overflow/underflow) are disabled. a class b trap (illegal opcode, illegal bus access, etc.), however, will interrupt the atomic sequence, since it indicates a severe hardware problem. the interrupt inhibit caused by an atomic instruction gets active immediately, i.e. no other instruction will enter the pipeline except the one that follows the atomic instruction, and no interrupt request will be serviced in between. all instructions requiring multiple cycles or hold states are regarded as one instruction in this sense (e.g. mul is one instruction). any instruction type can be used within an unseparable code sequence. atomic #3 ;the next 3 instr. are locked (no nop requ.) mov r0, #1234h ;instr. 1 (no other instr. enters pipeline!) mov r1, #5678h ;instr. 2 mul r0, r1 ;instr. 3: mul regarded as one instruction mov r2, mdl ;this instruction is out of the scope... ;...of the atomic instruction sequence 20.9 overriding the dpp addressing mechanism the standard mechanism to access data locations uses one of the four data page pointers (dppx), which selects a 16 kbyte data page, and a 14-bit offset within this data page. the four dpps allow immediate access to up to 64 kbyte of data. in applications with big data arrays, especially in hll applications using large memory models, this may require frequent reloading of the dpps, even for single accesses. the extp (extend page) instruction allows switching to an arbitrary data page for 1...4 instructions without having to change the current dpps. extp r15, #1 ;the override page number is stored in r15 mov r0, [r14] ;the (14-bit) page offset is stored in r14 mov r1, [r13] ;this instruction uses the std. dpp scheme!
 #   user ? s manual 20-15 1999-08  the exts (extend segment) instruction allows switching to a 64 kbyte segment oriented data access scheme for 1...4 instructions without having to change the current dpps. in this case all 16 bits of the operand address are used as segment offset, with the segment taken from the exts instruction. this greatly simplifies address calculation with continuous data like huge arrays in ? c ? . exts #15, #1 ;the override seg. is 15 (0f ? 0000h..0f ? ffffh) mov r0, [r14] ;the (16 -bit) segment offset is stored in r14 mov r1, [r13] ;this instruction uses the std. dpp scheme! note: instructions extp and exts inhibit interrupts the same way as atomic. short addressing in the extended sfr (esfr) space the short addressing modes of the c161pi (reg or bitoff) implicitly access the sfr space. the additional esfr space would have to be accessed via long addressing modes (mem or [rw]). the extr (extend register) instruction redirects accesses in short addressing modes to the esfr space for 1...4 instructions, so the additional registers can be accessed this way, too. the extpr and extsr instructions combine the dpp override mechanism with the redirection to the esfr space using a single instruction. note: instructions extr, extpr and extsr inhibit interrupts the same way as atomic. the switching to the esfr area and data page overriding is checked by the development tools or handled automatically. nested locked sequences each of the described extension instruction and the atomic instruction starts an internal ? extension counter ? counting the effected instructions. when another extension or atomic instruction is contained in the current locked sequence this counter is restarted with the value of the new instruction. this allows the construction of locked sequences longer than 4 instructions. note:  interrupt latencies may be increased when using locked code sequences.  pec requests are not serviced during idle mode, if the idle instruction is part of a locked sequence.
 #   user ? s manual 20-16 1999-08  20.10 handling the internal code memory the mask-rom/otp/flash versions of the c161pi provide on-chip code memory that may store code as well as data. the lower 32 kbyte of this code memory are referred to as the ? internal rom area ? . access to this internal rom area is controlled during the reset configuration and via software. the rom area may be mapped to segment 0, to segment 1 or the code memory may be disabled at all. note: the internal rom area always occupies an address area of 32 kbyte, even if the implemented mask rom/otp/flash memory is smaller than that (e.g. 8 kbyte). of course the total implemented memory may exceed 32 kbytes. code memory configuration during reset the control input pin ea (external access) enables the user to define the address area from which the first instructions after reset are fetched. when ea is low ( ? 0 ? ) during reset, the internal code memory is disabled and the first instructions are fetched from external memory. when ea is high ( ? 1 ? ) during reset, the internal code memory is globally enabled and the first instructions are fetched from the internal memory. note: be sure not to select internal memory access after reset on romless devices. mapping the internal rom area after reset the internal rom area is mapped into segment 0, the ? system segment ? (00 ? 0000 h ...00 ? 7fff h ) as a default. this is necessary to allow the first instructions to be fetched from locations 00 ? 0000 h ff. the rom area may be mapped to segment 1 (01 ? 0000 h ...01 ? 7fff h ) by setting bit roms1 in register syscon. the internal rom area may now be accessed through the lower half of segment 1, while accesses to segment 0 will now be made to external memory. this adds flexibility to the system software. the interrupt/trap vector table, which uses locations 00 ? 0000 h through 00 ? 01ff h , is now part of the external memory and may therefore be modified, i.e. the system software may now change interrupt/trap handlers according to the current condition of the system. the internal code memory can still be used for fixed software routines like io drivers, math libraries, application specific invariant routines, tables, etc. this combines the advantage of an integrated non-volatile memory with the advantage of a flexible, adaptable software system.
 #   user ? s manual 20-17 1999-08  enabling and disabling the internal code memory after reset if the internal code memory does not contain an appropriate startup code, the system may be booted from external memory, while the internal memory is enabled afterwards to provide access to library routines, tables, etc. if the internal code memory only contains the startup code and/or test software, the system may be booted from internal memory, which may then be disabled, after the software has switched to executing from (e.g.) external memory, in order to free the address space occupied by the internal code memory, which is now unnecessary.
 #   user ? s manual 20-18 1999-08  20.11 pits, traps and mines although handling the internal code memory provides powerful means to enhance the overall performance and flexibility of a system, extreme care must be taken in order to avoid a system crash. instruction memory is the most crucial resource for the c161pi and it must be made sure that it never runs out of it. the following precautions help to take advantage of the methods mentioned above without jeopardizing system security. internal code memory access after reset: when the first instructions are to be fetched from internal memory (ea= ? 1 ? ), the device must contain code memory, and this must contain a valid reset vector and valid code at its destination. mapping the internal rom area to segment 1: due to instruction pipelining, any new rom mapping will at the earliest become valid for the second instruction after the instruction which has changed the rom mapping. to enable accesses to the rom area after mapping a branch to the newly selected rom area (jmps) and reloading of all data page pointers is required. this also applies to re-mapping the internal rom area to segment 0. enabling the internal code memory after reset: when enabling the internal code memory after having booted the system from external memory, note that the c161pi will then access the internal memory using the current segment offset, rather than accessing external memory. disabling the internal code memory after reset: when disabling the internal code memory after having booted the system from there, note that the c161pi will not access external memory before a jump to segment 0 (in this case) is executed. general rules when mapping the code memory no instruction or data accesses should be made to the internal memory, otherwise unpredictable results may occur. to avoid these problems, the instructions that configure the internal code memory should be executed from external memory or from the on-chip ram. whenever the internal code memory is disabled, enabled or remapped the dpps must be explicitly (re)loaded to enable correct data accesses to the internal and/or external memory.
 ) # user ? s manual 21-1 1999-08  21 the register set this section summarizes all registers, which are implemented in the c161pi and explains the description format which is used in the chapters describing the function and layout of the sfrs. for easy reference the registers are ordered according to two different keys (except for gprs):  ordered by address, to check which register a given address references,  ordered by register name, to find the location of a specific register. 21.1 register description format in the respective chapters the function and the layout of the sfrs is described in a specific format which provides a number of details about the described special function register. the example below shows how to interpret these details. elements: reg_name short name of this register a16 / a8 long 16-bit address / short 8-bit address sfr /esfr / xreg register space (sfr, esfr or external/xbus register) (* *) * * register contents after reset 0/1 : defined value, ? x ? : undefined, u ? : unchanged (undefined ( ? x ? ) after power up) r/w access modes: can be r ead and/or w rite bits that are set/cleared by hardware are marked with a shaded access box and an ? h ? in it. reg_name name of register e/sfr (a16 h /a8 h ) reset value: * * * * h 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 std hw read/ write bit read bit write bit bitfield - - - - - - - - rw rwh rw r w rw bit function bit(field)name explanation of bit(field)name description of the functions controlled by the different possible values of this bit(field) . *h
 ) # user ? s manual 21-2 1999-08  21.2 cpu general purpose registers (gprs) the gprs form the register bank that the cpu works with. this register bank may be located anywhere within the internal ram via the context pointer (cp). due to the addressing mechanism, gpr banks can only reside within the internal ram. all gprs are bit-addressable. table 21-1 general purpose word registers name physical address 8-bit address description reset value r0 (cp) + 0 f0 h cpu general purpose (word) reg. r0 uuuu h r1 (cp) + 2 f1 h cpu general purpose (word) reg. r1 uuuu h r2 (cp) + 4 f2 h cpu general purpose (word) reg. r2 uuuu h r3 (cp) + 6 f3 h cpu general purpose (word) reg. r3 uuuu h r4 (cp) + 8 f4 h cpu general purpose (word) reg. r4 uuuu h r5 (cp) + 10 f5 h cpu general purpose (word) reg. r5 uuuu h r6 (cp) + 12 f6 h cpu general purpose (word) reg. r6 uuuu h r7 (cp) + 14 f7 h cpu general purpose (word) reg. r7 uuuu h r8 (cp) + 16 f8 h cpu general purpose (word) reg. r8 uuuu h r9 (cp) + 18 f9 h cpu general purpose (word) reg. r9 uuuu h r10 (cp) + 20 fa h cpu general purpose (word) reg. r10 uuuu h r11 (cp) + 22 fb h cpu general purpose (word) reg. r11 uuuu h r12 (cp) + 24 fc h cpu general purpose (word) reg. r12 uuuu h r13 (cp) + 26 fd h cpu general purpose (word) reg. r13 uuuu h r14 (cp) + 28 fe h cpu general purpose (word) reg. r14 uuuu h r15 (cp) + 30 ff h cpu general purpose (word) reg. r15 uuuu h
 ) # user ? s manual 21-3 1999-08  the first 8 gprs (r7...r0) may also be accessed bytewise. other than with sfrs, writing to a gpr byte does not affect the other byte of the respective gpr. the respective halves of the byte-accessible registers receive special names: table 21-2 general purpose byte registers name physical address 8-bit address description reset value rl0 (cp) + 0 f0 h cpu general purpose (byte) reg. rl0 uu h rh0 (cp) + 1 f1 h cpu general purpose (byte) reg. rh0 uu h rl1 (cp) + 2 f2 h cpu general purpose (byte) reg. rl1 uu h rh1 (cp) + 3 f3 h cpu general purpose (byte) reg. rh1 uu h rl2 (cp) + 4 f4 h cpu general purpose (byte) reg. rl2 uu h rh2 (cp) + 5 f5 h cpu general purpose (byte) reg. rh2 uu h rl3 (cp) + 6 f6 h cpu general purpose (byte) reg. rl3 uu h rh3 (cp) + 7 f7 h cpu general purpose (byte) reg. rh3 uu h rl4 (cp) + 8 f8 h cpu general purpose (byte) reg. rl4 uu h rh4 (cp) + 9 f9 h cpu general purpose (byte) reg. rh4 uu h rl5 (cp) + 10 fa h cpu general purpose (byte) reg. rl5 uu h rh5 (cp) + 11 fb h cpu general purpose (byte) reg. rh5 uu h rl6 (cp) + 12 fc h cpu general purpose (byte) reg. rl6 uu h rh6 (cp) + 13 fd h cpu general purpose (byte) reg. rh6 uu h rl7 (cp) + 14 fe h cpu general purpose (byte) reg. rl7 uu h rh7 (cp) + 14 ff h cpu general purpose (byte) reg. rh7 uu h
 ) # user ? s manual 21-4 1999-08  21.3 special function registers ordered by name the following table lists all sfrs which are implemented in the c161pi in alphabetical order. bit-addressable sfrs are marked with the letter ? b ? in column ? name ? . sfrs within the extended sfr-space (esfrs) are marked with the letter ? e ? in column ? physical address ? . registers within on-chip x-peripherals are marked with the letter ? x ? in column ? physical address ? . table 21-3 c161pi registers, ordered by name name physical address 8-bit addr. description reset value mdl fe0e h 07 h cpu multiply divide reg. ? low word 0000 h adcic b ff98 h cc h a/d converter end of conversion interrupt control register 0000 h adcon b ffa0 h d0 h a/d converter control register 0000 h addat fea0 h 50 h a/d converter result register 0000 h addat2 f0a0 h e 50 h a/d converter 2 result register 0000 h addrsel1 fe18 h 0c h address select register 1 0000 h addrsel2 fe1a h 0d h address select register 2 0000 h addrsel3 fe1c h 0e h address select register 3 0000 h addrsel4 fe1e h 0f h address select register 4 0000 h adeic b ff9a h cd h a/d converter overrun error interrupt control register 0000 h buscon0 b ff0c h 86 h bus configuration register 0 0000 h buscon1 b ff14 h 8a h bus configuration register 1 0000 h buscon2 b ff16 h 8b h bus configuration register 2 0000 h buscon3 b ff18 h 8c h bus configuration register 3 0000 h buscon4 b ff1a h 8d h bus configuration register 4 0000 h caprel fe4a h 25 h gpt2 capture/reload register 0000 h cc10ic b ff8c h c6 h external interrupt 2 control register 0000 h cc11ic b ff8e h c7 h external interrupt 3 control register 0000 h cc12ic b ff90 h c8 h external interrupt 4 control register 0000 h cc13ic b ff92 h c9 h external interrupt 5 control register 0000 h cc14ic b ff94 h ca h external interrupt 6 control register 0000 h
 ) # user ? s manual 21-5 1999-08  cc15ic b ff96 h cb h external interrupt 7 control register 0000 h cc8ic b ff88 h c4 h external interrupt 0 control register 0000 h cc9ic b ff8a h c5 h external interrupt 1 control register 0000 h cp fe10 h 08 h cpu context pointer register fc00 h cric b ff6a h b5 h gpt2 caprel interrupt ctrl. register 0000 h csp fe08 h 04 h cpu code segment pointer register (8 bits, not directly writeable) 0000 h dp0h b f102 h e 81 h p0h direction control register 00 h dp0l b f100 h e 80 h p0l direction control register 00 h dp1h b f106 h e 83 h p1h direction control register 00 h dp1l b f104 h e 82 h p1l direction control register 00 h dp2 b ffc2 h e1 h port 2 direction control register 0000 h dp3 b ffc6 h e3 h port 3 direction control register 0000 h dp4 b ffca h e5 h port 4 direction control register 00 h dp6 b ffce h e7 h port 6 direction control register 00 h dpp0 fe00 h 00 h cpu data page pointer 0 register (10 bits) 0000 h dpp1 fe02 h 01 h cpu data page pointer 1 reg. (10 bits) 0001 h dpp2 fe04 h 02 h cpu data page pointer 2 reg. (10 bits) 0002 h dpp3 fe06 h 03 h cpu data page pointer 3 reg. (10 bits) 0003 h exicon b f1c0 h e e0 h external interrupt control register 0000 h icadr ed06 h x --- i 2 c address register 0xxx h iccfg ed00 h x --- i 2 c configuration register xx00 h iccon ed02 h x --- i 2 c control register 0000 h icrtb ed08 h x --- i 2 c receive/transmit buffer xx h icst ed04 h x --- i 2 c status register 0000 h idchip f07c h e 3e h identifier 09xx h idmanuf f07e h e 3f h identifier 1820 h idmem f07a h e 3d h identifier 0000 h idprog f078 h e 3c h identifier 0000 h table 21-3 c161pi registers, ordered by name (cont ? d) name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-6 1999-08  isnc b f1de h e ef h interrupt subnode control register 0000 h mdc b ff0e h 87 h cpu multiply divide control register 0000 h mdh fe0c h 06 h cpu multiply divide reg. ? high word 0000 h odp2 b f1c2 h e e1 h port 2 open drain control register 0000 h odp3 b f1c6 h e e3 h port 3 open drain control register 0000 h odp6 b f1ce h e e7 h port 6 open drain control register 00 h ones b ff1e h 8f h constant value 1 ? s register (read only) ffff h p0h b ff02 h 81 h port 0 high reg. (upper half of port0) 00 h p0l b ff00 h 80 h port 0 low reg. (lower half of port0) 00 h p1h b ff06 h 83 h port 1 high reg. (upper half of port1) 00 h p1l b ff04 h 82 h port 1 low reg. (lower half of port1) 00 h p2 b ffc0 h e0 h port 2 register 0000 h p3 b ffc4 h e2 h port 3 register 0000 h p4 b ffc8 h e4 h port 4 register (7 bits) 00 h p5 b ffa2 h d1 h port 5 register (read only) xxxx h p5didis b ffa4 h d2 h port 5 digital input disable register 0000 h p6 b ffcc h e6 h port 6 register (8 bits) 00 h pdcr f0aa h e 55 h pin driver control register 0000 h pecc0 fec0 h 60 h pec channel 0 control register 0000 h pecc1 fec2 h 61 h pec channel 1 control register 0000 h pecc2 fec4 h 62 h pec channel 2 control register 0000 h pecc3 fec6 h 63 h pec channel 3 control register 0000 h pecc4 fec8 h 64 h pec channel 4 control register 0000 h pecc5 feca h 65 h pec channel 5 control register 0000 h pecc6 fecc h 66 h pec channel 6 control register 0000 h pecc7 fece h 67 h pec channel 7 control register 0000 h psw b ff10 h 88 h cpu program status word 0000 h rp0h b f108 h e 84 h system startup config. reg. (rd. only) xx h rtch f0d6 h e 6b h rtc high register no rtcl f0d4 h e 6a h rtc low register no table 21-3 c161pi registers, ordered by name (cont ? d) name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-7 1999-08  s0bg feb4 h 5a h serial channel 0 baud rate generator reload register 0000 h s0con b ffb0 h d8 h serial channel 0 control register 0000 h s0eic b ff70 h b8 h serial channel 0 error interrupt control register 0000 h s0rbuf feb2 h 59 h serial channel 0 receive buffer reg. (read only) xxxx h s0ric b ff6e h b7 h serial channel 0 receive interrupt control register 0000 h s0tbic b f19c h e ce h serial channel 0 transmit buffer interrupt control register 0000 h s0tbuf feb0 h 58 h serial channel 0 transmit buffer reg. (write only) 0000 h s0tic b ff6c h b6 h serial channel 0 transmit interrupt control register 0000 h sp fe12 h 09 h cpu system stack pointer register fc00 h sscbr f0b4 h e 5a h ssc baudrate register 0000 h ssccon b ffb2 h d9 h ssc control register 0000 h ssceic b ff76 h bb h ssc error interrupt control register 0000 h sscrb f0b2 h e 59 h ssc receive buffer xxxx h sscric b ff74 h ba h ssc receive interrupt control register 0000 h ssctb f0b0 h e 58 h ssc transmit buffer 0000 h ssctic b ff72 h b9 h ssc transmit interrupt control register 0000 h stkov fe14 h 0a h cpu stack overflow pointer register fa00 h stkun fe16 h 0b h cpu stack underflow pointer register fc00 h syscon b ff12 h 89 h cpu system configuration register 1) 0xx0 h syscon2 b f1d0 h e e8 h cpu system configuration register 2 0000 h syscon3 b f1d4 h e ea h cpu system configuration register 3 0000 h t14 f0d2 h e 69 h rtc timer 14 register no t14rel f0d0 h e 68 h rtc timer 14 reload register no t2 fe40 h 20 h gpt1 timer 2 register 0000 h table 21-3 c161pi registers, ordered by name (cont ? d) name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-8 1999-08  t2con b ff40 h a0 h gpt1 timer 2 control register 0000 h t2ic b ff60 h b0 h gpt1 timer 2 interrupt control register 0000 h t3 fe42 h 21 h gpt1 timer 3 register 0000 h t3con b ff42 h a1 h gpt1 timer 3 control register 0000 h t3ic b ff62 h b1 h gpt1 timer 3 interrupt control register 0000 h t4 fe44 h 22 h gpt1 timer 4 register 0000 h t4con b ff44 h a2 h gpt1 timer 4 control register 0000 h t4ic b ff64 h b2 h gpt1 timer 4 interrupt control register 0000 h t5 fe46 h 23 h gpt2 timer 5 register 0000 h t5con b ff46 h a3 h gpt2 timer 5 control register 0000 h t5ic b ff66 h b3 h gpt2 timer 5 interrupt control register 0000 h t6 fe48 h 24 h gpt2 timer 6 register 0000 h t6con b ff48 h a4 h gpt2 timer 6 control register 0000 h t6ic b ff68 h b4 h gpt2 timer 6 interrupt control register 0000 h tfr b ffac h d6 h trap flag register 0000 h wdt feae h 57 h watchdog timer register (read only) 0000 h wdtcon ffae h d7 h watchdog timer control register 2) 00xx h xp0ic b f186 h e c3 h i 2 c data interrupt control register 0000 h xp1ic b f18e h e c7 h i 2 c protocol interrupt control register 0000 h xp2ic b f196 h e cb h x-peripheral 2 interrupt control register 0000 h xp3ic b f19e h e cf h rtc interrupt control register 0000 h zeros b ff1c h 8e h constant value 0 ? s register (read only) 0000 h 1) the system configuration is selected during reset. 2) the reset value depends on the indicated reset source. table 21-3 c161pi registers, ordered by name (cont ? d) name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-9 1999-08  21.4 registers ordered by address the following table lists all sfrs which are implemented in the c161pi ordered by their physical address. bit-addressable sfrs are marked with the letter ? b ? in column ? name ? . sfrs within the extended sfr-space (esfrs) are marked with the letter ? e ? in column ? physical address ? . registers within on-chip x-peripherals are marked with the letter ? x ? in column ? physical address ? . table 21-4 c161pi registers, ordered by address name physical address 8-bit addr. description reset value iccfg ed00 h x --- i 2 c configuration register xx00 h iccon ed02 h x --- i 2 c control register 0000 h icst ed04 h x --- i 2 c status register 0000 h icadr ed06 h x --- i 2 c address register 0xxx h icrtb ed08 h x --- i 2 c receive/transmit buffer xx h idprog f078 h e 3c h identifier 0000 h idmem f07a h e 3d h identifier 0000 h idchip f07c h e 3e h identifier 09xx h idmanuf f07e h e 3f h identifier 1820 h addat2 f0a0 h e 50 h a/d converter 2 result register 0000 h pdcr f0aa h e 55 h pin driver control register 0000 h ssctb f0b0 h e 58 h ssc transmit buffer 0000 h sscrb f0b2 h e 59 h ssc receive buffer xxxx h sscbr f0b4 h e 5a h ssc baudrate register 0000 h t14rel f0d0 h e 68 h rtc timer 14 reload register no t14 f0d2 h e 69 h rtc timer 14 register no rtcl f0d4 h e 6a h rtc low register no rtch f0d6 h e 6b h rtc high register no dp0l b f100 h e 80 h p0l direction control register 00 h dp0h b f102 h e 81 h p0h direction control register 00 h dp1l b f104 h e 82 h p1l direction control register 00 h dp1h b f106 h e 83 h p1h direction control register 00 h rp0h b f108 h e 84 h system startup config. reg. (rd. only) xx h
 ) # user ? s manual 21-10 1999-08  xp0ic b f186 h e c3 h i 2 c data interrupt control register 0000 h xp1ic b f18e h e c7 h i 2 c protocol interrupt control register 0000 h xp2ic b f196 h e cb h x-peripheral 2 interrupt control register 0000 h s0tbic b f19c h e ce h serial channel 0 transmit buffer interrupt control register 0000 h xp3ic b f19e h e cf h rtc interrupt control register 0000 h exicon b f1c0 h e e0 h external interrupt control register 0000 h odp2 b f1c2 h e e1 h port 2 open drain control register 0000 h odp3 b f1c6 h e e3 h port 3 open drain control register 0000 h odp6 b f1ce h e e7 h port 6 open drain control register 00 h syscon2 b f1d0 h e e8 h cpu system configuration register 2 0000 h syscon3 b f1d4 h e ea h cpu system configuration register 3 0000 h isnc b f1de h e ef h interrupt subnode control register 0000 h dpp0 fe00 h 00 h cpu data page pointer 0 register (10 bits) 0000 h dpp1 fe02 h 01 h cpu data page pointer 1 reg. (10 bits) 0001 h dpp2 fe04 h 02 h cpu data page pointer 2 reg. (10 bits) 0002 h dpp3 fe06 h 03 h cpu data page pointer 3 reg. (10 bits) 0003 h csp fe08 h 04 h cpu code segment pointer register (8 bits, not directly writeable) 0000 h mdh fe0c h 06 h cpu multiply divide reg. ? high word 0000 h mdl fe0e h 07 h cpu multiply divide reg. ? low word 0000 h cp fe10 h 08 h cpu context pointer register fc00 h sp fe12 h 09 h cpu system stack pointer register fc00 h stkov fe14 h 0a h cpu stack overflow pointer register fa00 h stkun fe16 h 0b h cpu stack underflow pointer register fc00 h addrsel1 fe18 h 0c h address select register 1 0000 h addrsel2 fe1a h 0d h address select register 2 0000 h addrsel3 fe1c h 0e h address select register 3 0000 h addrsel4 fe1e h 0f h address select register 4 0000 h table 21-4 c161pi registers, ordered by address name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-11 1999-08  t2 fe40 h 20 h gpt1 timer 2 register 0000 h t3 fe42 h 21 h gpt1 timer 3 register 0000 h t4 fe44 h 22 h gpt1 timer 4 register 0000 h t5 fe46 h 23 h gpt2 timer 5 register 0000 h t6 fe48 h 24 h gpt2 timer 6 register 0000 h caprel fe4a h 25 h gpt2 capture/reload register 0000 h addat fea0 h 50 h a/d converter result register 0000 h wdt feae h 57 h watchdog timer register (read only) 0000 h s0tbuf feb0 h 58 h serial channel 0 transmit buffer reg. (write only) 0000 h s0rbuf feb2 h 59 h serial channel 0 receive buffer reg. (read only) xxxx h s0bg feb4 h 5a h serial channel 0 baud rate generator reload register 0000 h pecc0 fec0 h 60 h pec channel 0 control register 0000 h pecc1 fec2 h 61 h pec channel 1 control register 0000 h pecc2 fec4 h 62 h pec channel 2 control register 0000 h pecc3 fec6 h 63 h pec channel 3 control register 0000 h pecc4 fec8 h 64 h pec channel 4 control register 0000 h pecc5 feca h 65 h pec channel 5 control register 0000 h pecc6 fecc h 66 h pec channel 6 control register 0000 h pecc7 fece h 67 h pec channel 7 control register 0000 h p0l b ff00 h 80 h port 0 low reg. (lower half of port0) 00 h p0h b ff02 h 81 h port 0 high reg. (upper half of port0) 00 h p1l b ff04 h 82 h port 1 low reg. (lower half of port1) 00 h p1h b ff06 h 83 h port 1 high reg. (upper half of port1) 00 h buscon0 b ff0c h 86 h bus configuration register 0 0000 h mdc b ff0e h 87 h cpu multiply divide control register 0000 h psw b ff10 h 88 h cpu program status word 0000 h syscon b ff12 h 89 h cpu system configuration register 1) 0xx0 h table 21-4 c161pi registers, ordered by address name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-12 1999-08  buscon1 b ff14 h 8a h bus configuration register 1 0000 h buscon2 b ff16 h 8b h bus configuration register 2 0000 h buscon3 b ff18 h 8c h bus configuration register 3 0000 h buscon4 b ff1a h 8d h bus configuration register 4 0000 h zeros b ff1c h 8e h constant value 0 ? s register (read only) 0000 h ones b ff1e h 8f h constant value 1 ? s register (read only) ffff h t2con b ff40 h a0 h gpt1 timer 2 control register 0000 h t3con b ff42 h a1 h gpt1 timer 3 control register 0000 h t4con b ff44 h a2 h gpt1 timer 4 control register 0000 h t5con b ff46 h a3 h gpt2 timer 5 control register 0000 h t6con b ff48 h a4 h gpt2 timer 6 control register 0000 h t2ic b ff60 h b0 h gpt1 timer 2 interrupt control register 0000 h t3ic b ff62 h b1 h gpt1 timer 3 interrupt control register 0000 h t4ic b ff64 h b2 h gpt1 timer 4 interrupt control register 0000 h t5ic b ff66 h b3 h gpt2 timer 5 interrupt control register 0000 h t6ic b ff68 h b4 h gpt2 timer 6 interrupt control register 0000 h cric b ff6a h b5 h gpt2 caprel interrupt ctrl. register 0000 h s0tic b ff6c h b6 h serial channel 0 transmit interrupt control register 0000 h s0ric b ff6e h b7 h serial channel 0 receive interrupt control register 0000 h s0eic b ff70 h b8 h serial channel 0 error interrupt control register 0000 h ssctic b ff72 h b9 h ssc transmit interrupt control register 0000 h sscric b ff74 h ba h ssc receive interrupt control register 0000 h ssceic b ff76 h bb h ssc error interrupt control register 0000 h cc8ic b ff88 h c4 h external interrupt 0 control register 0000 h cc9ic b ff8a h c5 h external interrupt 1 control register 0000 h cc10ic b ff8c h c6 h external interrupt 2 control register 0000 h cc11ic b ff8e h c7 h external interrupt 3 control register 0000 h table 21-4 c161pi registers, ordered by address name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-13 1999-08  cc12ic b ff90 h c8 h external interrupt 4 control register 0000 h cc13ic b ff92 h c9 h external interrupt 5 control register 0000 h cc14ic b ff94 h ca h external interrupt 6 control register 0000 h cc15ic b ff96 h cb h external interrupt 7 control register 0000 h adcic b ff98 h cc h a/d converter end of conversion interrupt control register 0000 h adeic b ff9a h cd h a/d converter overrun error interrupt control register 0000 h adcon b ffa0 h d0 h a/d converter control register 0000 h p5 b ffa2 h d1 h port 5 register (read only) xxxx h p5didis b ffa4 h d2 h port 5 digital input disable register 0000 h tfr b ffac h d6 h trap flag register 0000 h wdtcon ffae h d7 h watchdog timer control register 2) 00xx h s0con b ffb0 h d8 h serial channel 0 control register 0000 h ssccon b ffb2 h d9 h ssc control register 0000 h p2 b ffc0 h e0 h port 2 register 0000 h dp2 b ffc2 h e1 h port 2 direction control register 0000 h p3 b ffc4 h e2 h port 3 register 0000 h dp3 b ffc6 h e3 h port 3 direction control register 0000 h p4 b ffc8 h e4 h port 4 register (7 bits) 00 h dp4 b ffca h e5 h port 4 direction control register 00 h p6 b ffcc h e6 h port 6 register (8 bits) 00 h dp6 b ffce h e7 h port 6 direction control register 00 h 1) the system configuration is selected during reset. 2) the reset value depends on the indicated reset source. table 21-4 c161pi registers, ordered by address name physical address 8-bit addr. description reset value
 ) # user ? s manual 21-14 1999-08  21.5 special notes pec pointer registers the source and destination pointers for the peripheral event controller are mapped to a special area within the internal ram. pointers that are not occupied by the pec may therefore be used like normal ram. during power down mode or any warm reset the pec pointers are preserved. the pec and its registers are described in chapter ? interrupt and trap functions ? . gpr access in the esfr area the locations 00 ? f000 h ...00 ? f01e h within the esfr area are reserved and allow to access the current register bank via short register addressing modes. the gprs are mirrored to the esfr area which allows access to the current register bank even after switching register spaces (see example below). mov r5, dp3 ;gpr access via sfr area extr #1 mov r5, odp3 ;gpr access via esfr area writing bytes to sfrs all special function registers may be accessed wordwise or bytewise (some of them even bitwise). reading bytes from word sfrs is a non-critical operation. however, when writing bytes to word sfrs the complementary byte of the respective sfr is cleared with the write operation.
   ##  user ? s manual 22-1 1999-08  22 instruction set summary this chapter briefly summarizes the c161pi ? s instructions ordered by instruction classes. this provides a basic understanding of the c161pi ? s instruction set, the power and versatility of the instructions and their general usage. a detailed description of each single instruction, including its operand data type, condition flag settings, addressing modes, length (number of bytes) and object code format is provided in the ? instruction set manual ? for the c166 family. this manual also provides tables ordering the instructions according to various criteria, to allow quick references. summary of instruction classes grouping the various instruction into classes aids in identifying similar instructions (e.g. shr, ror) and variations of certain instructions (e.g. add, addb). this provides an easy access to the possibilities and the power of the instructions of the c161pi. note: the used mnemonics refer to the detailled description. arithmetic instructions  addition of two words or bytes: add addb  addition with carry of two words or bytes: addc addcb  subtraction of two words or bytes: sub subb  subtraction with carry of two words or bytes: subc subcb  16 * 16 bit signed or unsigned multiplication: mul mulu  16/16 bit signed or unsigned division: div divu  32/16 bit signed or unsigned division: divl divlu  1's complement of a word or byte: cpl cplb  2's complement (negation) of a word or byte: neg negb logical instructions  bitwise anding of two words or bytes: and andb  bitwise oring of two words or bytes: or orb  bitwise xoring of two words or bytes: xor xorb compare and loop control instructions  comparison of two words or bytes: cmp cmpb  comparison of two words with post-increment by either 1 or 2: cmpi1 cmpi2  comparison of two words with post-decrement by either 1 or 2: cmpd1 cmpd2
   ##  user ? s manual 22-2 1999-08  boolean bit manipulation instructions  manipulation of a maskable bit field in either the high or the low byte of a word: bfldh bfldl  setting a single bit (to ? 1 ? ): bset  clearing a single bit (to ? 0 ? ): bclr  movement of a single bit: bmov  movement of a negated bit: bmovn  anding of two bits: band  oring of two bits: bor  xoring of two bits: bxor  comparison of two bits: bcmp shift and rotate instructions  shifting right of a word: shr  shifting left of a word: shl  rotating right of a word: ror  rotating left of a word: rol  arithmetic shifting right of a word (sign bit shifting): ashr prioritize instruction  determination of the number of shift cycles required to normalize a word operand (floating point support):prior data movement instructions  standard data movement of a word or byte: mov movb  data movement of a byte to a word location with either sign or zero byte extension: movbs movbz note: the data movement instructions can be used with a big number of different addressing modes including indirect addressing and automatic pointer in-/ decrementing. system stack instructions  pushing of a word onto the system stack: push  popping of a word from the system stack: pop  saving of a word on the system stack, and then updating the old word with a new value (provided for register bank switching): scxt
   ##  user ? s manual 22-3 1999-08  jump instructions  conditional jumping to an either absolutely, indirectly, or relatively addressed target instruction within the current code segment: jmpa jmpi jmpr  unconditional jumping to an absolutely addressed target instruction within any code segment: jmps  conditional jumping to a relatively addressed target instruction within the current code segment depending on the state of a selectable bit: jb jnb  conditional jumping to a relatively addressed target instruction within the current code segment depending on the state of a selectable bit with a post-inversion of the tested bit in case of jump taken (semaphore support): jbc jnbs call instructions  conditional calling of an either absolutely or indirectly addressed subroutine within the current code segment: calla calli  unconditional calling of a relatively addressed subroutine within the current code segment: callr  unconditional calling of an absolutely addressed subroutine within any code segment: calls  unconditional calling of an absolutely addressed subroutine within the current code segment plus an additional pushing of a selectable register onto the system stack: pcall  unconditional branching to the interrupt or trap vector jump table in code segment 0: trap return instructions  returning from a subroutine within the current code segment: ret  returning from a subroutine within any code segment: rets  returning from a subroutine within the current code segment plus an additional popping of a selectable register from the system stack: retp  returning from an interrupt service routine: reti
   ##  user ? s manual 22-4 1999-08  system control instructions  resetting the c161pi via software: srst  entering the idle mode: idle  entering the power down mode: pwrdn  servicing the watchdog timer: srvwdt  disabling the watchdog timer: diswdt  signifying the end of the initialization routine (pulls pin rstout high, and disables the effect of any later execution of a diswdt instruction): einit miscellaneous  null operation which requires 2 bytes of storage and the minimum time for execution: nop  definition of an unseparable instruction sequence: atomic  switch ? reg ? , ? bitoff ? and ? bitaddr ? addressing modes to the extended sfr space: extr  override the dpp addressing scheme using a specific data page instead of the dpps, and optionally switch to esfr space: extp extpr  override the dpp addressing scheme using a specific segment instead of the dpps, and optionally switch to esfr space: exts extsr note: the atomic and ext* instructions provide support for uninterruptable code sequences e.g. for semaphore operations. they also support data addressing beyond the limits of the current dpps (except atomic), which is advantageous for bigger memory models in high level languages. refer to chapter ? system programming ? for examples. protected instructions some instructions of the c161pi which are critical for the functionality of the controller are implemented as so-called protected instructions. these protected instructions use the maximum instruction format of 32 bits for decoding, while the regular instructions only use a part of it (e.g. the lower 8 bits) with the other bits providing additional information like involved registers. decoding all 32 bits of a protected doubleword instruction increases the security in cases of data distortion during instruction fetching. critical operations like a software reset are therefore only executed if the complete instruction is decoded without an error. this enhances the safety and reliability of a microcontroller system.
 ( #! 1   user ? s manual 23-1 1999-08  23 device specification the device specification describes the electrical parameters of the device. it lists dc characteristics like input, output or supply voltages or currents, and ac characteristics like timing characteristics and requirements. other than the architecture, the instruction set or the basic functions of the c161pi core and its peripherals, these dc and ac characteristics are subject to changes due to device improvements or specific derivatives of the standard device. therefore these characteristics are not contained in this manual, but rather provided in a separate data sheet, which can be updated more frequently. please refer to the current version of the data sheet of the respective device for all electrical parameters. note: in any case the specific characteristics of a device should be verified, before a new design is started. this ensures that the used information is up to date. the figures below show the pin diagrams of the c161pi. they show the location of the different supply and io pins. a detailed description of all the pins is also found in the data sheet. note: not all alternate functions shown in the figure below are supported by all derivatives. please refer to the corresponding descriptions in the data sheets.
 ( #! 1   user ? s manual 23-2 1999-08  figure 23-1 pin description for c161pi, p-mqfp-100 package 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 c161pi 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 nmi rstout rstin v dd v ss p1h.7/a15 p1h.6/a14 p1h.5/a13 p1h.4/a12 p1h.3/a11 p1h.2/a10 p1h.1/a9 p1h.0/a8 v dd v ss p1l.7/a7 p1l.6/a6 p1l.5/a5 p1l.4/a4 p1l.3/a3 p1l.2/a2 p1l.1/a1 p1l.0/a0 p0h.7/ad15 p0h.6/ad14 p0h.5/ad13 p0h.4/ad12 p0h.3/ad11 p0h.2/ad10 p0h.1/ad9 p5.2/an2 p5.3/an3 p5.14/t4eud p5.15/t2eud v ss xtal1 xtal2 v dd p3.0/scl0 p3.1/sda0 p3.2/capin p3.3/t3out p3.4/t3eud p3.5/t4in p3.6/t3in p3.7/t2in p3.8/mrst p3.9/mtsr p3.10/txd0 p3.11/rxd0 p3.12/bhe /wrh p3.13/sclk p3.15/clkout/fout v ss v dd p4.0/a16 p4.1/a17 p4.2/a18 p4.3/a19 p4.4/a20 p5.1/an1 p5.0/an0 v agnd v aref p2.15/ex7in p2.14/ex6in p2.13/ex5in p2.12/ex4in p2.11/ex3in p2.10/ex2in p2.9/ex1in p2.8/ex0in p6.7/sda2 p6.6/scl1 p6.5/sda1 p6.4/cs4 p6.3/cs3 p6.2/cs2 p6.1/cs1 p6.0/cs0 p4.5/a21 p4.6/a22 rd wr /wrl ready ale ea v ss v dd p0l.0/ad0 p0l.1/ad1 p0l.2/ad2 p0l.3/ad3 p0l.4/ad4 p0l.5/ad5 p0l.6/ad6 p0l.7/ad7 v ss v dd p0h.0/ad8
 ( #! 1   user ? s manual 23-3 1999-08  figure 23-2 pin description for c161pi, p-tqfp-100 package p5.3/an3 p5.2/an2 p5.1/an1 p5.0/an0 v agnd v aref p2.15/ex7in p2.14/ex6in p2.13/ex5in p2.12/ex4in p2.11/ex3in p2.10/ex2in p2.9/ex1in p2.8/ex0in p6.7/sda2 p6.6/scl1 p6.5/sda1 p6.4/cs4 p6.3/cs3 p6.2/cs2 p6.1/cs1 p6.0/cs0 nmi rstout rstin 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 c161pi 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 v dd v ss p1h.7/a15 p1h.6/a14 p1h.5/a13 p1h.4/a12 p1h.3/a11 p1h.2/a10 p1h.1/a9 p1h.0/a8 v dd v ss p1l.7/a7 p1l.6/a6 p1l.5/a5 p1l.4/a4 p1l.3/a3 p1l.2/a2 p1l.1/a1 p1l.0/a0 p0h.7/ad15 p0h.6/ad14 p0h.5/ad13 p0h.4/ad12 p0h.3/ad11 p5.14/t4eud p5.15/t2eud v ss xtal1 xtal2 v dd p3.0/scl0 p3.1/sda0 p3.2/capin p3.3/t3out p3.4/t3eud p3.5/t4in p3.6/t3in p3.7/t2in p3.8/mrst p3.9/mtsr p3.10/txd0 p3.11/rxd0 p3.12/bhe /wrh p3.13/sclk p3.15/clkout/ fout v ss v dd p4.0/a16 p4.1/a17 p4.2/a18 p4.3/a19 p4.4/a20 p4.5/a21 p4.6/a22 rd wr /wrl ready ale ea v ss v dd p0l.0/ad0 p0l.1/ad1 p0l.2/ad2 p0l.3/ad3 p0l.4/ad4 p0l.5/ad5 p0l.6/ad6 p0l.7/ad7 v ss v dd p0h.0/ad8 p0h.1/ad9 p0h.2/ad10
 ( #! 1   user ? s manual 23-4 1999-08 
c161pi keyword index user ? s manual 24-1 1999-08 a acronyms 1-7 adapt mode 18-15 adc 2-14, 16-1 adcic, adeic 16-13 adcon 16-3 addat, addat2 16-4 address arbitration 9-25 area definition 9-24 boundaries 3-12 segment 9-9, 18-18 addrselx 9-22, 9-25 ale length 9-13 alternate signals 7-7 alu 4-17 analog/digital converter 2-14, 16-1 arbitration address 9-25 asc0 11-1 asynchronous mode 11-5 baudrate 11-11 error detection 11-10 interrupts 11-15 synchronous mode 11-8 asynchronous serial interface (->asc0) 11-1 auto scan conversion 16-6 b baudrate asc0 11-11 bootstrap loader 15-6 i2c bus 17-8 ssc 12-13 bhe 7-23, 9-9 bidirectional reset 18-4 bit addressable memory 3-4 handling 4-11 manipulation instructions 22-2 protected 2-20, 4-11 bootstrap loader 15-1, 18-16 boundaries 3-12 bus can 2-14 demultiplexed 9-5 idle state 9-27 mode configuration 9-3, 18-17 multiplexed 9-4 physical i2c 17-4 busconx 9-20, 9-25 c can interface 2-14 capture mode gpt1 10-21 gpt2 (caprel) 10-32 ccxic 5-27 chip select configuration 9-10, 18-18 latched/early 9-11 clock distribution 6-1, 19-14 generator modes 6-7, 18-19 output signal 19-16 code memory handling 20-16 concatenation of timers 10-17, 10-31 configuration address 9-9, 18-18 24 keyword index this section lists a number of keywords which refer to specific details of the c161pi in terms of its architecture, its functional units or functions. this helps to quickly find the answer to specific questions about the c161pi.
c161pi keyword index user ? s manual 24-2 1999-08 bus mode 9-3, 18-17 chip select 9-10, 18-18 pll 6-7, 18-19 reset 18-7, 18-12 special modes 18-16 write control 18-17 context pointer 4-25 switching 5-18 conversion analog/digital 16-1 auto scan 16-6 timing control 16-11 count direction 10-4 counter 10-8, 10-15, 10-30 cp 4-25 cpu 2-2, 4-1 cric 10-36 csp 4-21 d data page 4-23, 20-14 boundaries 3-12 delay read/write 9-16 demultiplexed bus 9-5 development support 1-6 direct drive 6-6 direction count 10-4 disable interrupt 5-15 peripheral 19-14 segmentation 4-16 division 4-31, 20-2 dp0l, dp0h 7-9 dp1l, dp1h 7-13 dp2 7-16 dp3 7-19 dp4 7-24 dp6 7-30 dpp 4-23, 20-14 e early chip select 9-11 edge characteristic (ports) 7-5 emulation mode 18-14 enable interrupt 5-15 peripheral 19-14 segmentation 4-16 xbus peripherals 9-28 error detection asc0 11-10 ssc 12-14 exicon 5-26 external bus 2-10 bus characteristics 9-12 to 9- 18 bus idle state 9-27 bus modes 9-3to9-8 fast interrupts 5-26 interrupts 5-24 interrupts during sleep mode 5- 28 startup configuration 18-13 f fast external interrupts 5-26 flags 4-17 to 4-20 focon 19-17 frequency output signal 19-16 full duplex 12-7 g gpr 3-6, 4-25, 21-2 gpt 2-15 gpt1 10-1 gpt2 10-23 h half duplex 12-10 hardware reset 18-2
c161pi keyword index user ? s manual 24-3 1999-08 traps 5-29 i i2c bus module 17-1 icadr 17-10 iccfg 17-8 iccon 17-9 icrtb 17-10 icst 17-11 idle mode 19-3 state (bus) 9-27 incremental interface 10-9 indication of reset source 13-6 input threshold 7-2 instruction 20-1, 22-1 bit manipulation 22-2 branch 4-5 pipeline 4-4 protected 22-4 timing 4-12 unseparable 20-14 interface can 2-14 external bus 9-1 i2c bus 17-1 serial async. (->asc0) 11-1 serial sync. (->ssc) 12-1 internal ram 3-4 interrupt during sleep mode 5-28 enable/disable 5-15 external 5-24 fast external 5-26 node sharing 5-23 priority 5-7 processing 5-1, 5-5 response times 5-18 rtc 14-3 sources 5-2 system 2-7, 5-2 vectors 5-2 ip 4-21 iram 3-4 status after reset 18-8 l latched chip select 9-11 m management peripheral 19-14 power 19-1 master mode i2c bus 17-6 mdc 4-33 mdh 4-31 mdl 4-32 memory 2-8 bit-addressable 3-4 code memory handling 20-16 external 3-11 ram/sfr 3-4 rom area 3-3 tri-state time 9-15 xram 3-9 memory cycle time 9-14 multimaster mode i2c bus 17-7 multiplexed bus 9-4 multiplication 4-31, 20-2 n nmi 5-1, 5-32 noise filter (ext. interrupts) 5-28 o odp2 7-16 odp3 7-19 odp6 7-30 ones 4-34 open drain mode 7-4 oscillator circuitry 6-2 watchdog 6-8, 18-19
c161pi keyword index user ? s manual 24-4 1999-08 p p0l, p0h 7-9 p1l, p1h 7-13 p2 7-16 p3 7-19 p4 7-24 p5 7-27 p5didis 7-28 p6 7-30 pdcr 7-6 pec 2-8, 3-7, 5-11 response times 5-21 peccx 5-11 peripheral enable/disable 19-14 management 19-14 summary 2-11 phase locked loop 6-1 picon 7-2 pins 8-1, 23-2, 23-3 in idle and power down mode 19-9 pipeline 4-4 effects 4-7 pll 6-1, 18-19 port 2-17 edge characteristic 7-5 input threshold 7-2 power down mode 19-7 power management 2-18, 19-1 prescaler 6-6 protected bits 2-20, 4-11 instruction 22-4 psw 4-17, 5-9 r ram extension 3-9 internal 3-4 read/write delay 9-16 ready 9-17 real time clock (->rtc) 14-1 registers 21-1 sorted by address 21-9 sorted by name 21-4 reset 18-1 bidirectional 18-4 configuration 18-7, 18-12 hardware 18-2 output 18-8 software 18-3 source indication 13-6 values 18-5 watchdog timer 18-3 rtc 2-16, 14-1 s s0bg 11-11 s0eic, s0ric, s0tic, s0tbic 11-15 s0rbuf 11-7, 11-9 s0tbuf 11-7, 11-9 security mechanism 19-20 segment address 9-9, 18-18 boundaries 3-12 segmentation 4-21 enable/disable 4-16 serial interface 2-13, 11-1 asynchronous 11-5 can 2-14 synchronous 11-8, 12-1 sfr 3-8, 21-4, 21-9 single chip mode 9-2 startup configuration 18-20 slave mode i2c bus 17-7 sleep mode 19-5 slow down mode 19-10 software reset 18-3 traps 5-29 source interrupt 5-2 reset 13-6
c161pi keyword index user ? s manual 24-5 1999-08 sp 4-28 special operation modes (config.) 18-16 ssc 12-1 baudrate generation 12-13 error detection 12-14 full duplex 12-7 half duplex 12-10 sscbr 12-13 ssceic, sscric, ssctic 12-16 sscrb, ssctb 12-8 stack 3-5, 4-28, 20-4 startup configuration 18-7, 18-12 external reset 18-13 single-chip 18-20 stkov 4-29 stkun 4-30 subroutine 20-10 synchronous serial interface (->ssc) 12-1 syscon 4-14, 9-19 syscon1 19-6 syscon2 19-12 syscon3 19-15 t t2con 10-13 t2ic, t3ic, t4ic 10-22 t3con 10-3 t4con 10-13 t5con 10-28 t5ic, t6ic 10-36 t6con 10-25 tfr 5-31 threshold 7-2 timer 2-15, 10-1, 10-23 auxiliary timer 10-13, 10-28 concatenation 10-17, 10-31 core timer 10-3, 10-25 tools 1-6 traps 5-4, 5-29 tri-state time 9-15 u unlock sequence 19-20 unseparable instructions 20-14 w waitstate memory cycle 9-14 tri-state 9-15 xbus peripheral 9-28 watchdog 2-16, 13-1 after reset 18-5 oscillator 6-8, 18-19 reset 18-3 wdt 13-2 x xbus 2-10, 9-28 enable peripherals 9-28 waitstates 9-28 xp0ic 17-13 xp1ic 17-13 xram status after reset 18-8 xram on-chip 3-9 z zeros 4-34
c161pi keyword index user ? s manual 24-6 1999-08

published by 1      &


▲Up To Search▲   

 
Price & Availability of SAFC166

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X